Skip to content

Commit

Permalink
chore(zero-client)!: Reduce exports (#3644)
Browse files Browse the repository at this point in the history
We do not need to expose these Replicache types...

This triggered a yak shave...

Add eslint rule to disable importing mod.ts and fix all the files.
  • Loading branch information
arv authored Jan 30, 2025
1 parent 4f09d4b commit 1e43c9a
Show file tree
Hide file tree
Showing 43 changed files with 218 additions and 222 deletions.
26 changes: 18 additions & 8 deletions eslint-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,52 @@
{
"group": [
"datadog/*",
"otel/*",
"replicache/*",
"replicache-perf/*",
"shared/*",
"zero/*",
"zero-advanced/*",
"zero-cache/*",
"zero-client/*",
"zero-integration-test/*",
"zero-protocol/*",
"zero-react/*",
"zero-schema/*",
"zero-solid/*",
"zero-vue/*",
"zql/*",
"zqlite/*"
"zqlite/*",
"zqlite-zql-test/*"
],
"message": "Use relative imports instead"
},
{
"group": ["**/mod.ts"],
"message": "Don't import from barrel files. Import from the specific module instead."
}
],
"paths": [
{"name": "datadog", "message": "Use relative imports instead"},
{"name": "otel", "message": "Use relative imports instead"},
{"name": "replicache", "message": "Use relative imports instead"},
{
"name": "replicache-perf",
"message": "Use relative imports instead"
},
{"name": "shared", "message": "Use relative imports instead"},
{"name": "zero", "message": "Use relative imports instead"},
{"name": "zero-advanced", "message": "Use relative imports instead"},
{"name": "zero-cache", "message": "Use relative imports instead"},
{"name": "zero-client", "message": "Use relative imports instead"},
{
"name": "zero-integration-test",
"message": "Use relative imports instead"
},
{"name": "zero-protocol", "message": "Use relative imports instead"},
{"name": "zero-react", "message": "Use relative imports instead"},
{"name": "zero-schema", "message": "Use relative imports instead"},
{"name": "zero-solid", "message": "Use relative imports instead"},
{"name": "zero-vue", "message": "Use relative imports instead"},
{"name": "zql", "message": "Use relative imports instead"},
{"name": "zqlite", "message": "Use relative imports instead"}
{"name": "zqlite", "message": "Use relative imports instead"},
{"name": "zqlite-zql-test", "message": "Use relative imports instead"}
]
// "message": "Use relative imports instead"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/replicache/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {ReadonlyJSONValue} from '../../shared/src/json.ts';
import type {MaybePromise} from '../../shared/src/types.ts';
import type {Hash} from './hash.ts';
import type {ReadonlyJSONValue, WriteTransaction} from './mod.ts';
import type {PullResponseV1, PullResponseV1Internal} from './puller.ts';
import type {ReadTransactionImpl} from './transactions.ts';
import type {ReadTransactionImpl, WriteTransaction} from './transactions.ts';

export type BeginPullResult = {
requestID: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/zero-cache/src/auth/write-authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import type {JSONValue} from '../../../shared/src/json.ts';
import {randInt} from '../../../shared/src/rand.ts';
import * as v from '../../../shared/src/valita.ts';
import type {Condition} from '../../../zero-protocol/src/ast.ts';
import {
primaryKeyValueSchema,
type PrimaryKeyValue,
} from '../../../zero-protocol/src/primary-key.ts';
import type {
CRUDOp,
DeleteOp,
InsertOp,
UpdateOp,
UpsertOp,
} from '../../../zero-protocol/src/mod.ts';
import {
primaryKeyValueSchema,
type PrimaryKeyValue,
} from '../../../zero-protocol/src/primary-key.ts';
} from '../../../zero-protocol/src/push.ts';
import type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';
import type {
PermissionsConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-cache/src/db/delete-lite-db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {rmSync} from 'fs';
import {rmSync} from 'node:fs';

export function deleteLiteDB(dbFile: string) {
for (const suffix of ['', '-wal', '-wal2', '-shm']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './current/control.ts';
export * from './current/data.ts';
export * from './current/downstream.ts';
export * from './current/path.ts';
export * from './current/status.ts';
export * from './current/upstream.ts';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Types are externally exported under stable versions. Code within
// zero-cache, on the contrary, should reference the files in
// current/* so that it is versioned with the latest version.
export * as v0 from './current/mod.ts';
export * as v0 from './current.ts';
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {expect, test} from 'vitest';
import {h64} from '../../../../../shared/src/hash.ts';
import * as v0 from './current.ts';
import {changeStreamMessageSchema} from './current/downstream.ts';
import {CHANGE_SOURCE_PATH} from './current/path.ts';
import {changeSourceUpstreamSchema} from './current/upstream.ts';
import {v0} from './mod.ts';

function t(
module: {
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-cache/src/services/life-cycle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LogContext} from '@rocicorp/logger';
import {resolver} from '@rocicorp/resolver';
import {pid} from 'process';
import {pid} from 'node:process';
import type {EventEmitter} from 'stream';
import {
singleProcessMode,
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-cache/src/services/mutagen/mutagen.pg-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {resolver} from '@rocicorp/resolver';
import {afterEach, beforeEach, describe, expect, test} from 'vitest';
import {createSilentLogContext} from '../../../../shared/src/logging-test-utils.ts';
import * as ErrorKind from '../../../../zero-protocol/src/error-kind-enum.ts';
import * as MutationType from '../../../../zero-protocol/src/mutation-type-enum.ts';
import {
type CRUDMutation,
type CRUDOp,
type UpsertOp,
} from '../../../../zero-protocol/src/mod.ts';
import * as MutationType from '../../../../zero-protocol/src/mutation-type-enum.ts';
} from '../../../../zero-protocol/src/push.ts';
import type {WriteAuthorizer} from '../../auth/write-authorizer.ts';
import * as Mode from '../../db/mode-enum.ts';
import {expectTables, testDBs} from '../../test/db.ts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {describe, expect, test} from 'vitest';
import {createSilentLogContext} from '../../../../shared/src/logging-test-utils.ts';
import type {Downstream} from '../../../../zero-protocol/src/down.ts';
import * as ErrorKind from '../../../../zero-protocol/src/error-kind-enum.ts';
import {
type Downstream,
type PokeEndMessage,
type PokePartMessage,
type PokeStartMessage,
} from '../../../../zero-protocol/src/mod.ts';
import type {
PokeEndMessage,
PokePartMessage,
PokeStartMessage,
} from '../../../../zero-protocol/src/poke.ts';
import type {JSONObject} from '../../types/bigint-json.ts';
import {ErrorForClient} from '../../types/error-for-client.ts';
import {Subscription} from '../../types/subscription.ts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
import * as v from '../../../../shared/src/valita.ts';
import type {AST} from '../../../../zero-protocol/src/ast.ts';
import {rowSchema} from '../../../../zero-protocol/src/data.ts';
import type {Downstream} from '../../../../zero-protocol/src/down.ts';
import type {
Downstream,
PokePartBody,
PokeStartBody,
RowPatchOp,
} from '../../../../zero-protocol/src/mod.ts';
} from '../../../../zero-protocol/src/poke.ts';
import {primaryKeyValueRecordSchema} from '../../../../zero-protocol/src/primary-key.ts';
import type {RowPatchOp} from '../../../../zero-protocol/src/row-patch.ts';
import type {JSONObject} from '../../types/bigint-json.ts';
import {getLogLevel} from '../../types/error-for-client.ts';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {createSilentLogContext} from '../../../../shared/src/logging-test-utils.
import {Queue} from '../../../../shared/src/queue.ts';
import {sleep} from '../../../../shared/src/sleep.ts';
import type {AST} from '../../../../zero-protocol/src/ast.ts';
import type {Downstream} from '../../../../zero-protocol/src/down.ts';
import * as ErrorKind from '../../../../zero-protocol/src/error-kind-enum.ts';
import {
type Downstream,
type ErrorBody,
type PokePartBody,
type PokeStartBody,
type QueriesPatch,
} from '../../../../zero-protocol/src/mod.ts';
import type {ErrorBody} from '../../../../zero-protocol/src/error.ts';
import type {
PokePartBody,
PokeStartBody,
} from '../../../../zero-protocol/src/poke.ts';
import type {QueriesPatch} from '../../../../zero-protocol/src/queries-patch.ts';
import {relationships} from '../../../../zero-schema/src/builder/relationship-builder.ts';
import {createSchema} from '../../../../zero-schema/src/builder/schema-builder.ts';
import {
Expand All @@ -23,6 +23,7 @@ import type {PermissionsConfig} from '../../../../zero-schema/src/compiled-permi
import {definePermissions} from '../../../../zero-schema/src/permissions.ts';
import type {ExpressionBuilder} from '../../../../zql/src/query/expression.ts';
import {Database} from '../../../../zqlite/src/db.ts';
import type {LogConfig} from '../../config/zero-config.ts';
import {StatementRunner} from '../../db/statements.ts';
import {testDBs} from '../../test/db.ts';
import {DbFile} from '../../test/lite.ts';
Expand Down Expand Up @@ -52,7 +53,6 @@ import {PipelineDriver} from './pipeline-driver.ts';
import {initViewSyncerSchema} from './schema/init.ts';
import {Snapshotter} from './snapshotter.ts';
import {pickToken, type SyncContext, ViewSyncerService} from './view-syncer.ts';
import type {LogConfig} from '../../config/zero-config.ts';

const SHARD_ID = 'ABC';
const logConfig: LogConfig = {
Expand Down
12 changes: 6 additions & 6 deletions packages/zero-cache/src/services/view-syncer/view-syncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {CustomKeyMap} from '../../../../shared/src/custom-key-map.ts';
import {must} from '../../../../shared/src/must.ts';
import {randInt} from '../../../../shared/src/rand.ts';
import type {AST} from '../../../../zero-protocol/src/ast.ts';
import type {
ChangeDesiredQueriesBody,
ChangeDesiredQueriesMessage,
} from '../../../../zero-protocol/src/change-desired-queries.ts';
import type {InitConnectionMessage} from '../../../../zero-protocol/src/connect.ts';
import type {Downstream} from '../../../../zero-protocol/src/down.ts';
import * as ErrorKind from '../../../../zero-protocol/src/error-kind-enum.ts';
import {
type ChangeDesiredQueriesBody,
type ChangeDesiredQueriesMessage,
type Downstream,
type InitConnectionMessage,
} from '../../../../zero-protocol/src/mod.ts';
import type {PermissionsConfig} from '../../../../zero-schema/src/compiled-permissions.ts';
import {transformAndHashQuery} from '../../auth/read-authorizer.ts';
import {stringify} from '../../types/bigint-json.ts';
Expand Down
10 changes: 4 additions & 6 deletions packages/zero-cache/src/workers/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import {startAsyncSpan, startSpan} from '../../../otel/src/span.ts';
import {version} from '../../../otel/src/version.ts';
import {unreachable} from '../../../shared/src/asserts.ts';
import * as valita from '../../../shared/src/valita.ts';
import type {ConnectedMessage} from '../../../zero-protocol/src/connect.ts';
import type {Downstream} from '../../../zero-protocol/src/down.ts';
import * as ErrorKind from '../../../zero-protocol/src/error-kind-enum.ts';
import {type ErrorBody} from '../../../zero-protocol/src/error.ts';
import {
type ConnectedMessage,
type Downstream,
type PongMessage,
upstreamSchema,
} from '../../../zero-protocol/src/mod.ts';
import type {PongMessage} from '../../../zero-protocol/src/pong.ts';
import {
MIN_SERVER_SUPPORTED_PROTOCOL_VERSION,
PROTOCOL_VERSION,
} from '../../../zero-protocol/src/protocol-version.ts';
import {upstreamSchema} from '../../../zero-protocol/src/up.ts';
import type {ConnectParams} from '../services/dispatcher/connect-params.ts';
import type {Mutagen} from '../services/mutagen/mutagen.ts';
import type {
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-cache/src/workers/syncer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {LogContext} from '@rocicorp/logger';
import {resolver} from '@rocicorp/resolver';
import {type JWTPayload} from 'jose';
import {pid} from 'process';
import {MessagePort} from 'worker_threads';
import {pid} from 'node:process';
import {MessagePort} from 'node:worker_threads';
import {WebSocketServer, type WebSocket} from 'ws';
import {promiseVoid} from '../../../shared/src/resolved-promises.ts';
import * as ErrorKind from '../../../zero-protocol/src/error-kind-enum.ts';
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-client/src/client/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
import type {ExperimentalNoIndexDiff} from '../../../replicache/src/mod.ts';
import type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';
import {assert} from '../../../shared/src/asserts.ts';
import {createSchema} from '../../../zero-schema/src/builder/schema-builder.ts';
import {string, table} from '../../../zero-schema/src/builder/table-builder.ts';
Expand Down Expand Up @@ -235,7 +235,7 @@ test('transactions', () => {
});
const out = new Catch(join);

const changes: ExperimentalNoIndexDiff = [
const changes: NoIndexDiff = [
{
key: `${ENTITIES_KEY_PREFIX}server/s1`,
op: 'add',
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-client/src/client/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ExperimentalNoIndexDiff} from '../../../replicache/src/mod.ts';
import type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';
import {assert, unreachable} from '../../../shared/src/asserts.ts';
import type {AST} from '../../../zero-protocol/src/ast.ts';
import type {Row} from '../../../zero-protocol/src/data.ts';
Expand Down Expand Up @@ -89,7 +89,7 @@ export class ZeroContext implements QueryDelegate {
return result as T;
}

processChanges(changes: ExperimentalNoIndexDiff) {
processChanges(changes: NoIndexDiff) {
try {
this.batchViewUpdates(() => {
for (const diff of changes) {
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-client/src/client/crud.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {Expand} from '../../../shared/src/expand.ts';
import type {ReadonlyJSONObject} from '../../../shared/src/json.ts';
import {promiseVoid} from '../../../shared/src/resolved-promises.ts';
import type {MaybePromise} from '../../../shared/src/types.ts';
import {
Expand All @@ -11,12 +12,11 @@ import {
type UpdateOp,
type UpsertOp,
} from '../../../zero-protocol/src/push.ts';
import type {Schema} from '../../../zero-schema/src/mod.ts';
import type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';
import type {
SchemaValueToTSType,
TableSchema,
} from '../../../zero-schema/src/table-schema.ts';
import type {ReadonlyJSONObject} from '../mod.ts';
import {toPrimaryKeyString} from './keys.ts';
import type {MutatorDefs, WriteTransaction} from './replicache-types.ts';

Expand Down
11 changes: 3 additions & 8 deletions packages/zero-client/src/client/custom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import type {
DeleteID,
InsertValue,
Schema,
TableSchema,
UpdateValue,
UpsertValue,
} from '../mod.ts';
import type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';
import type {TableSchema} from '../../../zero-schema/src/table-schema.ts';
import type {ClientID} from '../types/client-state.ts';
import type {DeleteID, InsertValue, UpdateValue, UpsertValue} from './crud.ts';

/**
* The shape which a user's custom mutator definitions must conform to.
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-client/src/client/log-options.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {consoleLogSink, type LogSink} from '@rocicorp/logger';
import * as sinon from 'sinon';
import {afterEach, beforeEach, expect, suite, test} from 'vitest';
import type {DatadogLogSinkOptions} from '../../../datadog/src/mod.ts';
import type {DatadogLogSinkOptions} from '../../../datadog/src/datadog-log-sink.ts';
import {TestLogSink} from '../../../shared/src/logging-test-utils.ts';
import type {HTTPString} from './http-string.ts';
import {createLogOptions} from './log-options.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/zero-client/src/client/log-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import {
DatadogLogSink,
type DatadogLogSinkOptions,
} from '../../../datadog/src/mod.ts';
} from '../../../datadog/src/datadog-log-sink.ts';
import {appendPath, type HTTPString} from './http-string.ts';
import {version} from './version.ts';

Expand Down
8 changes: 4 additions & 4 deletions packages/zero-client/src/client/options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {LogLevel} from '@rocicorp/logger';
import type {KVStoreProvider} from '../../../replicache/src/mod.ts';
import type {StoreProvider} from '../../../replicache/src/kv/store.ts';
import type {MaybePromise} from '../../../shared/src/types.ts';
import type {Schema} from '../../../zero-schema/src/mod.ts';
import type {Schema} from '../../../zero-schema/src/builder/schema-builder.ts';
import type {CustomMutatorDefs} from './custom.ts';

/**
* Configuration for [[Zero]].
* Configuration for {@linkcode Zero}.
*/
export interface ZeroOptions<
S extends Schema,
Expand Down Expand Up @@ -135,7 +135,7 @@ export interface ZeroOptions<
* You can also set this to a function that is used to create new KV stores,
* allowing a custom implementation of the underlying storage layer.
*/
kvStore?: 'mem' | 'idb' | KVStoreProvider | undefined;
kvStore?: 'mem' | 'idb' | StoreProvider | undefined;

/**
* The maximum number of bytes to allow in a single header.
Expand Down
Loading

0 comments on commit 1e43c9a

Please sign in to comment.