@rocicorp/zero 0.18.2025031801 → 0.18.2025032000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/advanced.js +1 -1
- package/out/{chunk-5X3DESC6.js → chunk-2B2QE5AT.js} +2 -3
- package/out/{chunk-5X3DESC6.js.map → chunk-2B2QE5AT.js.map} +2 -2
- package/out/{chunk-MJCITZ5S.js → chunk-2NCGIK6G.js} +2 -2
- package/out/{chunk-MJCITZ5S.js.map → chunk-2NCGIK6G.js.map} +2 -2
- package/out/{chunk-472VY5VS.js → chunk-6AOMML7A.js} +73 -31
- package/out/chunk-6AOMML7A.js.map +7 -0
- package/out/react.js +1 -1
- package/out/replicache/src/dag/lazy-store.d.ts.map +1 -1
- package/out/replicache/src/dag/store-impl.d.ts.map +1 -1
- package/out/replicache/src/replicache-impl.d.ts +2 -2
- package/out/replicache/src/replicache-impl.d.ts.map +1 -1
- package/out/replicache/src/replicache-options.d.ts +3 -0
- package/out/replicache/src/replicache-options.d.ts.map +1 -1
- package/out/shared/src/has-own.d.ts +1 -4
- package/out/shared/src/has-own.d.ts.map +1 -1
- package/out/shared/src/has-own.js +2 -7
- package/out/shared/src/has-own.js.map +1 -1
- package/out/shared/src/hash.d.ts.map +1 -1
- package/out/shared/src/immutable.d.ts.map +1 -1
- package/out/shared/src/options.d.ts.map +1 -1
- package/out/shared/src/options.js.map +1 -1
- package/out/shared/src/ref-count.d.ts +16 -0
- package/out/shared/src/ref-count.d.ts.map +1 -0
- package/out/shared/src/valita.js +1 -1
- package/out/shared/src/valita.js.map +1 -1
- package/out/solid.js +37 -5
- package/out/solid.js.map +3 -3
- package/out/z2s/src/compiler.d.ts +28 -14
- package/out/z2s/src/compiler.d.ts.map +1 -1
- package/out/z2s/src/compiler.js +181 -121
- package/out/z2s/src/compiler.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +1 -0
- package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +2 -0
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/specs.d.ts +6 -6
- package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/db/warmup.d.ts +4 -0
- package/out/zero-cache/src/db/warmup.d.ts.map +1 -0
- package/out/zero-cache/src/db/warmup.js +13 -0
- package/out/zero-cache/src/db/warmup.js.map +1 -0
- package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +2 -1
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +4 -7
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/multi/run-worker.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/run-worker.js +2 -7
- package/out/zero-cache/src/server/multi/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/server/syncer.js +3 -2
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +15 -15
- package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts +6 -6
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +8 -8
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +12 -12
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +4 -4
- package/out/zero-cache/src/services/life-cycle.d.ts +2 -1
- package/out/zero-cache/src/services/life-cycle.d.ts.map +1 -1
- package/out/zero-cache/src/services/life-cycle.js +9 -1
- package/out/zero-cache/src/services/life-cycle.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
- package/out/zero-cache/src/services/runner.d.ts.map +1 -1
- package/out/zero-cache/src/services/runner.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +1 -0
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
- package/out/zero-cache/src/types/pg.d.ts.map +1 -1
- package/out/zero-cache/src/types/pg.js +2 -2
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/processes.js +9 -1
- package/out/zero-cache/src/types/processes.js.map +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts +1 -1
- package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer.js +1 -0
- package/out/zero-cache/src/workers/syncer.js.map +1 -1
- package/out/zero-client/src/client/context.d.ts +1 -0
- package/out/zero-client/src/client/context.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +4 -12
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-rep.d.ts +7 -1
- package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-pg/src/custom.d.ts +4 -5
- package/out/zero-pg/src/custom.d.ts.map +1 -1
- package/out/zero-pg/src/custom.js.map +1 -1
- package/out/zero-pg/src/query.d.ts.map +1 -1
- package/out/zero-pg/src/query.js +7 -4
- package/out/zero-pg/src/query.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.js +2 -1
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-schema/src/builder/schema-builder.d.ts +0 -1
- package/out/zero-schema/src/builder/schema-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
- package/out/zero-schema/src/name-mapper.js +2 -2
- package/out/zero-schema/src/name-mapper.js.map +1 -1
- package/out/zero-schema/src/table-schema.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero.js +3 -3
- package/out/zql/src/builder/builder.d.ts +7 -0
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +1 -1
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/ivm/take.d.ts +3 -0
- package/out/zql/src/ivm/take.d.ts.map +1 -1
- package/out/zql/src/ivm/take.js +33 -7
- package/out/zql/src/ivm/take.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +1 -1
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/custom.d.ts +10 -10
- package/out/zql/src/mutate/custom.d.ts.map +1 -1
- package/out/zql/src/query/expression.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +3 -3
- package/out/chunk-472VY5VS.js.map +0 -7
package/out/advanced.js
CHANGED
|
@@ -33,8 +33,7 @@ function compareTTL(a, b) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// ../shared/src/has-own.ts
|
|
36
|
-
var
|
|
37
|
-
var hasOwn = Object.hasOwn || ((object, key) => objectPrototypeHasOwnProperty.call(object, key));
|
|
36
|
+
var { hasOwn } = Object;
|
|
38
37
|
|
|
39
38
|
export {
|
|
40
39
|
hasOwn,
|
|
@@ -42,4 +41,4 @@ export {
|
|
|
42
41
|
parseTTL,
|
|
43
42
|
compareTTL
|
|
44
43
|
};
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-2B2QE5AT.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../zql/src/query/ttl.ts", "../../shared/src/has-own.ts"],
|
|
4
|
-
"sourcesContent": ["export type TimeUnit = 's' | 'm' | 'h' | 'd' | 'y';\n\n/**\n * Time To Live. This is used for query expiration.\n * - `forever` means the query will never expire.\n * - `none` means the query will expire immediately.\n * - A number means the query will expire after that many milliseconds.\n * - A negative number means the query will never expire, this is same as 'forever'.\n * - A string like `1s` means the query will expire after that many seconds.\n * - A string like `1m` means the query will expire after that many minutes.\n * - A string like `1h` means the query will expire after that many hours.\n * - A string like `1d` means the query will expire after that many days.\n * - A string like `1y` means the query will expire after that many years.\n */\nexport type TTL = `${number}${TimeUnit}` | 'forever' | 'none' | number;\n\nexport const DEFAULT_TTL: TTL = 'none';\n\nconst multiplier = {\n s: 1000,\n m: 60 * 1000,\n h: 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n y: 365 * 24 * 60 * 60 * 1000,\n} as const;\n\nexport function parseTTL(ttl: TTL): number {\n if (typeof ttl === 'number') {\n return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;\n }\n if (ttl === 'none') {\n return 0;\n }\n if (ttl === 'forever') {\n return -1;\n }\n const multi = multiplier[ttl[ttl.length - 1] as TimeUnit];\n return Number(ttl.slice(0, -1)) * multi;\n}\n\nexport function compareTTL(a: TTL, b: TTL): number {\n const ap = parseTTL(a);\n const bp = parseTTL(b);\n if (ap === -1 && bp !== -1) {\n return 1;\n }\n if (ap !== -1 && bp === -1) {\n return -1;\n }\n return ap - bp;\n}\n\nexport function normalizeTTL(ttl: TTL): string | number {\n if (typeof ttl === 'string') {\n return ttl;\n }\n\n if (ttl < 0) {\n return 'forever';\n }\n\n if (ttl === 0) {\n return 'none';\n }\n\n let shortest = ttl.toString();\n const lengthOfNumber = shortest.length;\n for (const unit of ['y', 'd', 'h', 'm', 's'] as const) {\n const multi = multiplier[unit];\n const value = ttl / multi;\n const candidate = `${value}${unit}`;\n if (candidate.length < shortest.length) {\n shortest = candidate;\n }\n }\n\n return shortest.length < lengthOfNumber ? shortest : ttl;\n}\n", "
|
|
5
|
-
"mappings": ";AAgBO,IAAM,cAAmB;AAEhC,IAAM,aAAa;AAAA,EACjB,GAAG;AAAA,EACH,GAAG,KAAK;AAAA,EACR,GAAG,KAAK,KAAK;AAAA,EACb,GAAG,KAAK,KAAK,KAAK;AAAA,EAClB,GAAG,MAAM,KAAK,KAAK,KAAK;AAC1B;AAEO,SAAS,SAAS,KAAkB;AACzC,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,SAAS,GAAG,KAAK,MAAM,IAAI,KAAK;AAAA,EACzE;AACA,MAAI,QAAQ,QAAQ;AAClB,WAAO;AAAA,EACT;AACA,MAAI,QAAQ,WAAW;AACrB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,WAAW,IAAI,IAAI,SAAS,CAAC,CAAa;AACxD,SAAO,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI;AACpC;AAEO,SAAS,WAAW,GAAQ,GAAgB;AACjD,QAAM,KAAK,SAAS,CAAC;AACrB,QAAM,KAAK,SAAS,CAAC;AACrB,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,SAAO,KAAK;AACd;;;
|
|
4
|
+
"sourcesContent": ["export type TimeUnit = 's' | 'm' | 'h' | 'd' | 'y';\n\n/**\n * Time To Live. This is used for query expiration.\n * - `forever` means the query will never expire.\n * - `none` means the query will expire immediately.\n * - A number means the query will expire after that many milliseconds.\n * - A negative number means the query will never expire, this is same as 'forever'.\n * - A string like `1s` means the query will expire after that many seconds.\n * - A string like `1m` means the query will expire after that many minutes.\n * - A string like `1h` means the query will expire after that many hours.\n * - A string like `1d` means the query will expire after that many days.\n * - A string like `1y` means the query will expire after that many years.\n */\nexport type TTL = `${number}${TimeUnit}` | 'forever' | 'none' | number;\n\nexport const DEFAULT_TTL: TTL = 'none';\n\nconst multiplier = {\n s: 1000,\n m: 60 * 1000,\n h: 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n y: 365 * 24 * 60 * 60 * 1000,\n} as const;\n\nexport function parseTTL(ttl: TTL): number {\n if (typeof ttl === 'number') {\n return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;\n }\n if (ttl === 'none') {\n return 0;\n }\n if (ttl === 'forever') {\n return -1;\n }\n const multi = multiplier[ttl[ttl.length - 1] as TimeUnit];\n return Number(ttl.slice(0, -1)) * multi;\n}\n\nexport function compareTTL(a: TTL, b: TTL): number {\n const ap = parseTTL(a);\n const bp = parseTTL(b);\n if (ap === -1 && bp !== -1) {\n return 1;\n }\n if (ap !== -1 && bp === -1) {\n return -1;\n }\n return ap - bp;\n}\n\nexport function normalizeTTL(ttl: TTL): string | number {\n if (typeof ttl === 'string') {\n return ttl;\n }\n\n if (ttl < 0) {\n return 'forever';\n }\n\n if (ttl === 0) {\n return 'none';\n }\n\n let shortest = ttl.toString();\n const lengthOfNumber = shortest.length;\n for (const unit of ['y', 'd', 'h', 'm', 's'] as const) {\n const multi = multiplier[unit];\n const value = ttl / multi;\n const candidate = `${value}${unit}`;\n if (candidate.length < shortest.length) {\n shortest = candidate;\n }\n }\n\n return shortest.length < lengthOfNumber ? shortest : ttl;\n}\n", "// hasOwn was added in ES2022\nexport const {hasOwn} = Object;\n"],
|
|
5
|
+
"mappings": ";AAgBO,IAAM,cAAmB;AAEhC,IAAM,aAAa;AAAA,EACjB,GAAG;AAAA,EACH,GAAG,KAAK;AAAA,EACR,GAAG,KAAK,KAAK;AAAA,EACb,GAAG,KAAK,KAAK,KAAK;AAAA,EAClB,GAAG,MAAM,KAAK,KAAK,KAAK;AAC1B;AAEO,SAAS,SAAS,KAAkB;AACzC,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,SAAS,GAAG,KAAK,MAAM,IAAI,KAAK;AAAA,EACzE;AACA,MAAI,QAAQ,QAAQ;AAClB,WAAO;AAAA,EACT;AACA,MAAI,QAAQ,WAAW;AACrB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,WAAW,IAAI,IAAI,SAAS,CAAC,CAAa;AACxD,SAAO,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI;AACpC;AAEO,SAAS,WAAW,GAAQ,GAAgB;AACjD,QAAM,KAAK,SAAS,CAAC;AACrB,QAAM,KAAK,SAAS,CAAC;AACrB,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,SAAO,KAAK;AACd;;;ACjDO,IAAM,EAAC,OAAM,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -167,7 +167,7 @@ function applyChange(parentEntry, change, schema, relationship, format) {
|
|
|
167
167
|
if (oldEntry !== void 0) {
|
|
168
168
|
assert(
|
|
169
169
|
schema.compareRows(oldEntry, change.node.row) === 0,
|
|
170
|
-
|
|
170
|
+
`Singular relationship '${relationship}' should not have multiple rows. You may need to declare this relationship with the \`many\` helper instead of the \`one\` helper in your schema.`
|
|
171
171
|
);
|
|
172
172
|
rc = oldEntry[refCountSymbol] + 1;
|
|
173
173
|
}
|
|
@@ -404,4 +404,4 @@ export {
|
|
|
404
404
|
drainStreams,
|
|
405
405
|
applyChange
|
|
406
406
|
};
|
|
407
|
-
//# sourceMappingURL=chunk-
|
|
407
|
+
//# sourceMappingURL=chunk-2NCGIK6G.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../shared/src/asserts.ts", "../../shared/src/must.ts", "../../zql/src/ivm/data.ts", "../../zql/src/ivm/view-apply-change.ts"],
|
|
4
|
-
"sourcesContent": ["export function assert(\n b: unknown,\n msg: string | (() => string) = 'Assertion failed',\n): asserts b {\n if (!b) {\n throw new Error(typeof msg === 'string' ? msg : msg());\n }\n}\n\nexport function assertString(v: unknown): asserts v is string {\n assertType(v, 'string');\n}\n\nexport function assertNumber(v: unknown): asserts v is number {\n assertType(v, 'number');\n}\n\nexport function assertBoolean(v: unknown): asserts v is boolean {\n assertType(v, 'boolean');\n}\n\nfunction assertType(v: unknown, t: string) {\n if (typeof v !== t) {\n throwInvalidType(v, t);\n }\n}\n\nexport function assertObject(v: unknown): asserts v is Record<string, unknown> {\n if (v === null) {\n throwInvalidType(v, 'object');\n }\n assertType(v, 'object');\n}\n\nexport function assertArray(v: unknown): asserts v is unknown[] {\n if (!Array.isArray(v)) {\n throwInvalidType(v, 'array');\n }\n}\n\nexport function invalidType(v: unknown, t: string): string {\n let s = 'Invalid type: ';\n if (v === null || v === undefined) {\n s += v;\n } else {\n s += `${typeof v} \\`${v}\\``;\n }\n return s + `, expected ${t}`;\n}\n\nexport function throwInvalidType(v: unknown, t: string): never {\n throw new Error(invalidType(v, t));\n}\n\nexport function assertNotNull<T>(v: T | null): asserts v is T {\n if (v === null) {\n throw new Error('Expected non-null value');\n }\n}\n\nexport function assertUndefined<T>(\n v: T | undefined,\n msg = 'Expected undefined value',\n): asserts v is T {\n if (v !== undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertNotUndefined<T>(\n v: T | undefined,\n msg = 'Expected non undefined value',\n): asserts v is T {\n if (v === undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertInstanceof<T>(\n v: unknown,\n t: new (...args: unknown[]) => T,\n): asserts v is T {\n if (!(v instanceof t)) {\n throw new Error(`Expected instanceof ${t.name}`);\n }\n}\n\nexport function assertUint8Array(v: unknown): asserts v is Uint8Array {\n assertInstanceof(v, Uint8Array);\n}\n\nexport function unreachable(): never;\nexport function unreachable(v: never): never;\nexport function unreachable(_?: never): never {\n throw new Error('Unreachable');\n}\n\nexport function notImplemented(): never {\n throw new Error('Not implemented');\n}\n", "export function must<T>(v: T | undefined | null, msg?: string): T {\n // eslint-disable-next-line eqeqeq\n if (v == null) {\n throw new Error(msg ?? `Unexpected ${v} value`);\n }\n return v;\n}\n", "import {compareUTF8} from 'compare-utf8';\nimport {\n assertBoolean,\n assertNumber,\n assertString,\n} from '../../../shared/src/asserts.ts';\nimport type {Ordering} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * A row flowing through the pipeline, plus its relationships.\n * Relationships are generated lazily as read.\n */\nexport type Node = {\n row: Row;\n relationships: Record<string, () => Stream<Node>>;\n};\n\n/**\n * Compare two values. The values must be of the same type. This function\n * throws at runtime if the types differ.\n *\n * Note, this function considers `null === null` and\n * `undefined === undefined`. This is different than SQL. In join code,\n * null must be treated separately.\n *\n * See: https://github.com/rocicorp/mono/pull/2116/files#r1704811479\n *\n * @returns < 0 if a < b, 0 if a === b, > 0 if a > b\n */\nexport function compareValues(a: Value, b: Value): number {\n a = normalizeUndefined(a);\n b = normalizeUndefined(b);\n\n if (a === b) {\n return 0;\n }\n if (a === null) {\n return -1;\n }\n if (b === null) {\n return 1;\n }\n if (typeof a === 'boolean') {\n assertBoolean(b);\n return a ? 1 : -1;\n }\n if (typeof a === 'number') {\n assertNumber(b);\n return a - b;\n }\n if (typeof a === 'string') {\n assertString(b);\n // We compare all strings in Zero as UTF-8. This is the default on SQLite\n // and we need to match it. See:\n // https://blog.replicache.dev/blog/replicache-11-adventures-in-text-encoding.\n //\n // TODO: We could change this since SQLite supports UTF-16. Microbenchmark\n // to see if there's a big win.\n //\n // https://www.sqlite.org/c3ref/create_collation.html\n return compareUTF8(a, b);\n }\n throw new Error(`Unsupported type: ${a}`);\n}\n\nexport type NormalizedValue = Exclude<Value, undefined>;\n\n/**\n * We allow undefined to be passed for the convenience of developers, but we\n * treat it equivalently to null. It's better for perf to not create an copy\n * of input values, so we just normalize at use when necessary.\n */\nexport function normalizeUndefined(v: Value): NormalizedValue {\n return v ?? null;\n}\n\nexport type Comparator = (r1: Row, r2: Row) => number;\n\nexport function makeComparator(\n order: Ordering,\n reverse?: boolean | undefined,\n): Comparator {\n return (a, b) => {\n // Skip destructuring here since it is hot code.\n for (const ord of order) {\n const field = ord[0];\n const comp = compareValues(a[field], b[field]);\n if (comp !== 0) {\n const result = ord[1] === 'asc' ? comp : -comp;\n return reverse ? -result : result;\n }\n }\n return 0;\n };\n}\n\n/**\n * Determine if two values are equal. Note that unlike compareValues() above,\n * this function treats `null` as unequal to itself (and same for `undefined`).\n * This is required to make joins work correctly, but may not be the right\n * semantic for your application.\n */\nexport function valuesEqual(a: Value, b: Value): boolean {\n // eslint-disable-next-line eqeqeq\n if (a == null || b == null) {\n return false;\n }\n return a === b;\n}\n\nexport function drainStreams(node: Node) {\n for (const stream of Object.values(node.relationships)) {\n for (const node of stream()) {\n drainStreams(node);\n }\n }\n}\n", "import {\n assert,\n assertArray,\n assertNumber,\n unreachable,\n} from '../../../shared/src/asserts.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Writable} from '../../../shared/src/writable.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport {drainStreams, type Comparator, type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Entry, Format} from './view.ts';\n\nexport const refCountSymbol = Symbol('rc');\n\ntype RCEntry = Writable<Entry> & {[refCountSymbol]: number};\ntype RCEntryList = RCEntry[];\n\n/**\n * `applyChange` does not consume the `relationships` of `ChildChange#node`,\n * `EditChange#node` and `EditChange#oldNode`. The `ViewChange` type\n * documents and enforces this via the type system.\n */\nexport type ViewChange =\n | AddViewChange\n | RemoveViewChange\n | ChildViewChange\n | EditViewChange;\n\nexport type RowOnlyNode = {row: Row};\n\nexport type AddViewChange = {\n type: 'add';\n node: Node;\n};\n\nexport type RemoveViewChange = {\n type: 'remove';\n node: Node;\n};\n\ntype ChildViewChange = {\n type: 'child';\n node: RowOnlyNode;\n child: {\n relationshipName: string;\n change: ViewChange;\n };\n};\n\ntype EditViewChange = {\n type: 'edit';\n node: RowOnlyNode;\n oldNode: RowOnlyNode;\n};\n\n/**\n * This is a subset of WeakMap but restricted to what we need.\n * @deprecated Not used anymore. This will be removed in the future.\n */\nexport interface RefCountMap {\n get(entry: Entry): number | undefined;\n set(entry: Entry, refCount: number): void;\n delete(entry: Entry): boolean;\n}\n\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n): void;\n/** @deprecated Use the version without the `refCountMap` parameter. */\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n refCountMap?: unknown,\n): void;\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n): void {\n if (schema.isHidden) {\n switch (change.type) {\n case 'add':\n case 'remove':\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n const childSchema = must(schema.relationships[relationship]);\n for (const node of children()) {\n applyChange(\n parentEntry,\n {type: change.type, node},\n childSchema,\n relationship,\n format,\n );\n }\n }\n return;\n case 'edit':\n // If hidden at this level it means that the hidden row was changed. If\n // the row was changed in such a way that it would change the\n // relationships then the edit would have been split into remove and\n // add.\n return;\n case 'child': {\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n applyChange(\n parentEntry,\n change.child.change,\n childSchema,\n relationship,\n format,\n );\n return;\n }\n default:\n unreachable(change);\n }\n }\n\n const {singular, relationships: childFormats} = format;\n switch (change.type) {\n case 'add': {\n let newEntry: RCEntry;\n\n let rc = 1;\n if (singular) {\n const oldEntry = parentEntry[relationship] as RCEntry | undefined;\n if (oldEntry !== undefined) {\n assert(\n schema.compareRows(oldEntry, change.node.row) === 0,\n 'single output already exists',\n );\n // adding same again.\n rc = oldEntry[refCountSymbol] + 1;\n }\n\n newEntry = makeNewEntryWithRefCount(change.node.row, rc);\n\n (parentEntry as Writable<Entry>)[relationship] = newEntry;\n } else {\n newEntry = makeNewEntryAndInsert(\n change.node.row,\n getChildEntryList(parentEntry, relationship),\n schema.compareRows,\n );\n }\n\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n // TODO: Is there a flag to make TypeScript complain that dictionary access might be undefined?\n const childSchema = must(schema.relationships[relationship]);\n const childFormat = childFormats[relationship];\n if (childFormat === undefined) {\n continue;\n }\n\n const newView = childFormat.singular ? undefined : ([] as RCEntryList);\n newEntry[relationship] = newView;\n\n for (const node of children()) {\n applyChange(\n newEntry,\n {type: 'add', node},\n childSchema,\n relationship,\n childFormat,\n );\n }\n }\n break;\n }\n case 'remove': {\n if (singular) {\n const oldEntry = parentEntry[relationship] as RCEntry | undefined;\n assert(oldEntry !== undefined, 'node does not exist');\n const rc = oldEntry[refCountSymbol];\n if (rc === 1) {\n (parentEntry as Writable<Entry>)[relationship] = undefined;\n }\n oldEntry[refCountSymbol]--;\n } else {\n removeAndUpdateRefCount(\n getChildEntryList(parentEntry, relationship),\n change.node.row,\n schema.compareRows,\n );\n }\n // Needed to ensure cleanup of operator state is fully done.\n drainStreams(change.node);\n break;\n }\n case 'child': {\n let existing: RCEntry;\n if (singular) {\n existing = getSingularEntry(parentEntry, relationship);\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n existing = view[pos];\n }\n\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n const childFormat = format.relationships[change.child.relationshipName];\n if (childFormat !== undefined) {\n applyChange(\n existing,\n change.child.change,\n childSchema,\n change.child.relationshipName,\n childFormat,\n );\n }\n break;\n }\n case 'edit': {\n if (singular) {\n const existing = parentEntry[relationship];\n assertRCEntry(existing);\n const rc = existing[refCountSymbol];\n const newEntry = {\n ...existing,\n ...change.node.row,\n [refCountSymbol]: rc,\n };\n existing[refCountSymbol] = 0;\n (parentEntry as Writable<Entry>)[relationship] = newEntry;\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n // If the order changed due to the edit, we need to remove and reinsert.\n if (schema.compareRows(change.oldNode.row, change.node.row) === 0) {\n const {pos, found} = binarySearch(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n const oldEntry = view[pos];\n const rc = oldEntry[refCountSymbol];\n oldEntry[refCountSymbol] = 0;\n\n const newEntry = makeEntryPreserveRelationships(\n change.node.row,\n oldEntry,\n format.relationships,\n rc,\n );\n\n view[pos] = newEntry;\n } else {\n // Remove\n const oldEntry = removeAndUpdateRefCount(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n\n // Insert\n insertAndSetRefCount(\n view,\n change.node.row,\n oldEntry,\n format.relationships,\n schema.compareRows,\n );\n }\n }\n\n break;\n }\n default:\n unreachable(change);\n }\n}\n\nfunction makeNewEntryAndInsert(\n newRow: Row,\n view: RCEntryList,\n compareRows: Comparator,\n): RCEntry {\n const {pos, found} = binarySearch(view, newRow, compareRows);\n\n let deleteCount = 0;\n let rc = 1;\n if (found) {\n deleteCount = 1;\n rc = view[pos][refCountSymbol];\n view[pos][refCountSymbol] = rc - 1;\n rc++;\n }\n\n const newEntry = makeNewEntryWithRefCount(newRow, rc);\n\n view.splice(pos, deleteCount, newEntry);\n\n return newEntry;\n}\n\nfunction insertAndSetRefCount(\n view: RCEntryList,\n newRow: Row,\n oldEntry: RCEntry,\n relationships: {[key: string]: Format},\n compareRows: Comparator,\n): void {\n const {pos, found} = binarySearch(view, newRow, compareRows);\n\n let deleteCount = 0;\n let rc = 1;\n if (found) {\n deleteCount = 1;\n const oldEntry = view[pos];\n rc = oldEntry[refCountSymbol] + 1;\n oldEntry[refCountSymbol] = 0;\n }\n\n const newEntry = makeEntryPreserveRelationships(\n newRow,\n oldEntry,\n relationships,\n rc,\n );\n\n view.splice(pos, deleteCount, newEntry);\n}\n\nfunction removeAndUpdateRefCount(\n view: RCEntryList,\n row: Row,\n compareRows: Comparator,\n): RCEntry {\n const {pos, found} = binarySearch(view, row, compareRows);\n assert(found, 'node does not exist');\n const oldEntry = view[pos];\n const rc = oldEntry[refCountSymbol];\n if (rc === 1) {\n view.splice(pos, 1);\n }\n oldEntry[refCountSymbol]--;\n\n return oldEntry;\n}\n\n// TODO: Do not return an object. It puts unnecessary pressure on the GC.\nfunction binarySearch(view: RCEntryList, target: Row, comparator: Comparator) {\n let low = 0;\n let high = view.length - 1;\n while (low <= high) {\n const mid = (low + high) >>> 1;\n const comparison = comparator(view[mid] as Row, target as Row);\n if (comparison < 0) {\n low = mid + 1;\n } else if (comparison > 0) {\n high = mid - 1;\n } else {\n return {pos: mid, found: true};\n }\n }\n return {pos: low, found: false};\n}\n\nfunction makeEntryPreserveRelationships(\n newRow: Row,\n oldEntry: RCEntry,\n relationships: {[key: string]: Format},\n rc: number,\n): RCEntry {\n const entry = makeNewEntryWithRefCount(newRow, rc);\n for (const relationship in relationships) {\n assert(!(relationship in newRow), 'Relationship already exists');\n entry[relationship] = oldEntry[relationship];\n }\n return entry;\n}\n\nfunction getChildEntryList(\n parentEntry: Entry,\n relationship: string,\n): RCEntryList {\n const view = parentEntry[relationship];\n assertArray(view);\n return view as RCEntryList;\n}\n\nfunction assertRCEntry(v: unknown): asserts v is RCEntry {\n assertNumber((v as Partial<RCEntry>)[refCountSymbol]);\n}\n\nfunction getSingularEntry(parentEntry: Entry, relationship: string): RCEntry {\n const e = parentEntry[relationship];\n assertNumber((e as Partial<RCEntry>)[refCountSymbol]);\n return e as RCEntry;\n}\n\nfunction makeNewEntryWithRefCount(row: Row, rc: number): RCEntry {\n return {...row, [refCountSymbol]: rc};\n}\n"],
|
|
5
|
-
"mappings": ";AAAO,SAAS,OACd,G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C,SAAS,YACd,aACA,QACA,QACA,cACA,QACM;AACN,MAAI,OAAO,UAAU;AACnB,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,KAAK;AACH,mBAAW,CAACC,eAAc,QAAQ,KAAK,OAAO;AAAA,UAC5C,OAAO,KAAK;AAAA,QACd,GAAG;AACD,gBAAM,cAAc,KAAK,OAAO,cAAcA,aAAY,CAAC;AAC3D,qBAAW,QAAQ,SAAS,GAAG;AAC7B;AAAA,cACE;AAAA,cACA,EAAC,MAAM,OAAO,MAAM,KAAI;AAAA,cACxB;AAAA,cACAA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AACA;AAAA,MACF,KAAK;AAKH;AAAA,MACF,KAAK,SAAS;AACZ,cAAM,cAAc;AAAA,UAClB,OAAO,cAAc,OAAO,MAAM,gBAAgB;AAAA,QACpD;AACA;AAAA,UACE;AAAA,UACA,OAAO,MAAM;AAAA,UACb;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA;AACE,oBAAY,MAAM;AAAA,IACtB;AAAA,EACF;AAEA,QAAM,EAAC,UAAU,eAAe,aAAY,IAAI;AAChD,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,OAAO;AACV,UAAI;AAEJ,UAAI,KAAK;AACT,UAAI,UAAU;AACZ,cAAM,WAAW,YAAY,YAAY;AACzC,YAAI,aAAa,QAAW;AAC1B;AAAA,YACE,OAAO,YAAY,UAAU,OAAO,KAAK,GAAG,MAAM;AAAA,YAClD;AAAA,
|
|
4
|
+
"sourcesContent": ["export function assert(\n b: unknown,\n msg: string | (() => string) = 'Assertion failed',\n): asserts b {\n if (!b) {\n throw new Error(typeof msg === 'string' ? msg : msg());\n }\n}\n\nexport function assertString(v: unknown): asserts v is string {\n assertType(v, 'string');\n}\n\nexport function assertNumber(v: unknown): asserts v is number {\n assertType(v, 'number');\n}\n\nexport function assertBoolean(v: unknown): asserts v is boolean {\n assertType(v, 'boolean');\n}\n\nfunction assertType(v: unknown, t: string) {\n if (typeof v !== t) {\n throwInvalidType(v, t);\n }\n}\n\nexport function assertObject(v: unknown): asserts v is Record<string, unknown> {\n if (v === null) {\n throwInvalidType(v, 'object');\n }\n assertType(v, 'object');\n}\n\nexport function assertArray(v: unknown): asserts v is unknown[] {\n if (!Array.isArray(v)) {\n throwInvalidType(v, 'array');\n }\n}\n\nexport function invalidType(v: unknown, t: string): string {\n let s = 'Invalid type: ';\n if (v === null || v === undefined) {\n s += v;\n } else {\n s += `${typeof v} \\`${v}\\``;\n }\n return s + `, expected ${t}`;\n}\n\nexport function throwInvalidType(v: unknown, t: string): never {\n throw new Error(invalidType(v, t));\n}\n\nexport function assertNotNull<T>(v: T | null): asserts v is T {\n if (v === null) {\n throw new Error('Expected non-null value');\n }\n}\n\nexport function assertUndefined<T>(\n v: T | undefined,\n msg = 'Expected undefined value',\n): asserts v is T {\n if (v !== undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertNotUndefined<T>(\n v: T | undefined,\n msg = 'Expected non undefined value',\n): asserts v is T {\n if (v === undefined) {\n throw new Error(msg);\n }\n}\n\nexport function assertInstanceof<T>(\n v: unknown,\n t: new (...args: unknown[]) => T,\n): asserts v is T {\n if (!(v instanceof t)) {\n throw new Error(`Expected instanceof ${t.name}`);\n }\n}\n\nexport function assertUint8Array(v: unknown): asserts v is Uint8Array {\n assertInstanceof(v, Uint8Array);\n}\n\nexport function unreachable(): never;\nexport function unreachable(v: never): never;\nexport function unreachable(_?: never): never {\n throw new Error('Unreachable');\n}\n\nexport function notImplemented(): never {\n throw new Error('Not implemented');\n}\n", "export function must<T>(v: T | undefined | null, msg?: string): T {\n // eslint-disable-next-line eqeqeq\n if (v == null) {\n throw new Error(msg ?? `Unexpected ${v} value`);\n }\n return v;\n}\n", "import {compareUTF8} from 'compare-utf8';\nimport {\n assertBoolean,\n assertNumber,\n assertString,\n} from '../../../shared/src/asserts.ts';\nimport type {Ordering} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * A row flowing through the pipeline, plus its relationships.\n * Relationships are generated lazily as read.\n */\nexport type Node = {\n row: Row;\n relationships: Record<string, () => Stream<Node>>;\n};\n\n/**\n * Compare two values. The values must be of the same type. This function\n * throws at runtime if the types differ.\n *\n * Note, this function considers `null === null` and\n * `undefined === undefined`. This is different than SQL. In join code,\n * null must be treated separately.\n *\n * See: https://github.com/rocicorp/mono/pull/2116/files#r1704811479\n *\n * @returns < 0 if a < b, 0 if a === b, > 0 if a > b\n */\nexport function compareValues(a: Value, b: Value): number {\n a = normalizeUndefined(a);\n b = normalizeUndefined(b);\n\n if (a === b) {\n return 0;\n }\n if (a === null) {\n return -1;\n }\n if (b === null) {\n return 1;\n }\n if (typeof a === 'boolean') {\n assertBoolean(b);\n return a ? 1 : -1;\n }\n if (typeof a === 'number') {\n assertNumber(b);\n return a - b;\n }\n if (typeof a === 'string') {\n assertString(b);\n // We compare all strings in Zero as UTF-8. This is the default on SQLite\n // and we need to match it. See:\n // https://blog.replicache.dev/blog/replicache-11-adventures-in-text-encoding.\n //\n // TODO: We could change this since SQLite supports UTF-16. Microbenchmark\n // to see if there's a big win.\n //\n // https://www.sqlite.org/c3ref/create_collation.html\n return compareUTF8(a, b);\n }\n throw new Error(`Unsupported type: ${a}`);\n}\n\nexport type NormalizedValue = Exclude<Value, undefined>;\n\n/**\n * We allow undefined to be passed for the convenience of developers, but we\n * treat it equivalently to null. It's better for perf to not create an copy\n * of input values, so we just normalize at use when necessary.\n */\nexport function normalizeUndefined(v: Value): NormalizedValue {\n return v ?? null;\n}\n\nexport type Comparator = (r1: Row, r2: Row) => number;\n\nexport function makeComparator(\n order: Ordering,\n reverse?: boolean | undefined,\n): Comparator {\n return (a, b) => {\n // Skip destructuring here since it is hot code.\n for (const ord of order) {\n const field = ord[0];\n const comp = compareValues(a[field], b[field]);\n if (comp !== 0) {\n const result = ord[1] === 'asc' ? comp : -comp;\n return reverse ? -result : result;\n }\n }\n return 0;\n };\n}\n\n/**\n * Determine if two values are equal. Note that unlike compareValues() above,\n * this function treats `null` as unequal to itself (and same for `undefined`).\n * This is required to make joins work correctly, but may not be the right\n * semantic for your application.\n */\nexport function valuesEqual(a: Value, b: Value): boolean {\n // eslint-disable-next-line eqeqeq\n if (a == null || b == null) {\n return false;\n }\n return a === b;\n}\n\nexport function drainStreams(node: Node) {\n for (const stream of Object.values(node.relationships)) {\n for (const node of stream()) {\n drainStreams(node);\n }\n }\n}\n", "import {\n assert,\n assertArray,\n assertNumber,\n unreachable,\n} from '../../../shared/src/asserts.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Writable} from '../../../shared/src/writable.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport {drainStreams, type Comparator, type Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Entry, Format} from './view.ts';\n\nexport const refCountSymbol = Symbol('rc');\n\ntype RCEntry = Writable<Entry> & {[refCountSymbol]: number};\ntype RCEntryList = RCEntry[];\n\n/**\n * `applyChange` does not consume the `relationships` of `ChildChange#node`,\n * `EditChange#node` and `EditChange#oldNode`. The `ViewChange` type\n * documents and enforces this via the type system.\n */\nexport type ViewChange =\n | AddViewChange\n | RemoveViewChange\n | ChildViewChange\n | EditViewChange;\n\nexport type RowOnlyNode = {row: Row};\n\nexport type AddViewChange = {\n type: 'add';\n node: Node;\n};\n\nexport type RemoveViewChange = {\n type: 'remove';\n node: Node;\n};\n\ntype ChildViewChange = {\n type: 'child';\n node: RowOnlyNode;\n child: {\n relationshipName: string;\n change: ViewChange;\n };\n};\n\ntype EditViewChange = {\n type: 'edit';\n node: RowOnlyNode;\n oldNode: RowOnlyNode;\n};\n\n/**\n * This is a subset of WeakMap but restricted to what we need.\n * @deprecated Not used anymore. This will be removed in the future.\n */\nexport interface RefCountMap {\n get(entry: Entry): number | undefined;\n set(entry: Entry, refCount: number): void;\n delete(entry: Entry): boolean;\n}\n\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n): void;\n/** @deprecated Use the version without the `refCountMap` parameter. */\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n refCountMap?: unknown,\n): void;\nexport function applyChange(\n parentEntry: Entry,\n change: ViewChange,\n schema: SourceSchema,\n relationship: string,\n format: Format,\n): void {\n if (schema.isHidden) {\n switch (change.type) {\n case 'add':\n case 'remove':\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n const childSchema = must(schema.relationships[relationship]);\n for (const node of children()) {\n applyChange(\n parentEntry,\n {type: change.type, node},\n childSchema,\n relationship,\n format,\n );\n }\n }\n return;\n case 'edit':\n // If hidden at this level it means that the hidden row was changed. If\n // the row was changed in such a way that it would change the\n // relationships then the edit would have been split into remove and\n // add.\n return;\n case 'child': {\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n applyChange(\n parentEntry,\n change.child.change,\n childSchema,\n relationship,\n format,\n );\n return;\n }\n default:\n unreachable(change);\n }\n }\n\n const {singular, relationships: childFormats} = format;\n switch (change.type) {\n case 'add': {\n let newEntry: RCEntry;\n\n let rc = 1;\n if (singular) {\n const oldEntry = parentEntry[relationship] as RCEntry | undefined;\n if (oldEntry !== undefined) {\n assert(\n schema.compareRows(oldEntry, change.node.row) === 0,\n `Singular relationship '${relationship}' should not have multiple rows. You may need to declare this relationship with the \\`many\\` helper instead of the \\`one\\` helper in your schema.`,\n );\n // adding same again.\n rc = oldEntry[refCountSymbol] + 1;\n }\n\n newEntry = makeNewEntryWithRefCount(change.node.row, rc);\n\n (parentEntry as Writable<Entry>)[relationship] = newEntry;\n } else {\n newEntry = makeNewEntryAndInsert(\n change.node.row,\n getChildEntryList(parentEntry, relationship),\n schema.compareRows,\n );\n }\n\n for (const [relationship, children] of Object.entries(\n change.node.relationships,\n )) {\n // TODO: Is there a flag to make TypeScript complain that dictionary access might be undefined?\n const childSchema = must(schema.relationships[relationship]);\n const childFormat = childFormats[relationship];\n if (childFormat === undefined) {\n continue;\n }\n\n const newView = childFormat.singular ? undefined : ([] as RCEntryList);\n newEntry[relationship] = newView;\n\n for (const node of children()) {\n applyChange(\n newEntry,\n {type: 'add', node},\n childSchema,\n relationship,\n childFormat,\n );\n }\n }\n break;\n }\n case 'remove': {\n if (singular) {\n const oldEntry = parentEntry[relationship] as RCEntry | undefined;\n assert(oldEntry !== undefined, 'node does not exist');\n const rc = oldEntry[refCountSymbol];\n if (rc === 1) {\n (parentEntry as Writable<Entry>)[relationship] = undefined;\n }\n oldEntry[refCountSymbol]--;\n } else {\n removeAndUpdateRefCount(\n getChildEntryList(parentEntry, relationship),\n change.node.row,\n schema.compareRows,\n );\n }\n // Needed to ensure cleanup of operator state is fully done.\n drainStreams(change.node);\n break;\n }\n case 'child': {\n let existing: RCEntry;\n if (singular) {\n existing = getSingularEntry(parentEntry, relationship);\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n const {pos, found} = binarySearch(\n view,\n change.node.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n existing = view[pos];\n }\n\n const childSchema = must(\n schema.relationships[change.child.relationshipName],\n );\n const childFormat = format.relationships[change.child.relationshipName];\n if (childFormat !== undefined) {\n applyChange(\n existing,\n change.child.change,\n childSchema,\n change.child.relationshipName,\n childFormat,\n );\n }\n break;\n }\n case 'edit': {\n if (singular) {\n const existing = parentEntry[relationship];\n assertRCEntry(existing);\n const rc = existing[refCountSymbol];\n const newEntry = {\n ...existing,\n ...change.node.row,\n [refCountSymbol]: rc,\n };\n existing[refCountSymbol] = 0;\n (parentEntry as Writable<Entry>)[relationship] = newEntry;\n } else {\n const view = getChildEntryList(parentEntry, relationship);\n // If the order changed due to the edit, we need to remove and reinsert.\n if (schema.compareRows(change.oldNode.row, change.node.row) === 0) {\n const {pos, found} = binarySearch(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n assert(found, 'node does not exist');\n const oldEntry = view[pos];\n const rc = oldEntry[refCountSymbol];\n oldEntry[refCountSymbol] = 0;\n\n const newEntry = makeEntryPreserveRelationships(\n change.node.row,\n oldEntry,\n format.relationships,\n rc,\n );\n\n view[pos] = newEntry;\n } else {\n // Remove\n const oldEntry = removeAndUpdateRefCount(\n view,\n change.oldNode.row,\n schema.compareRows,\n );\n\n // Insert\n insertAndSetRefCount(\n view,\n change.node.row,\n oldEntry,\n format.relationships,\n schema.compareRows,\n );\n }\n }\n\n break;\n }\n default:\n unreachable(change);\n }\n}\n\nfunction makeNewEntryAndInsert(\n newRow: Row,\n view: RCEntryList,\n compareRows: Comparator,\n): RCEntry {\n const {pos, found} = binarySearch(view, newRow, compareRows);\n\n let deleteCount = 0;\n let rc = 1;\n if (found) {\n deleteCount = 1;\n rc = view[pos][refCountSymbol];\n view[pos][refCountSymbol] = rc - 1;\n rc++;\n }\n\n const newEntry = makeNewEntryWithRefCount(newRow, rc);\n\n view.splice(pos, deleteCount, newEntry);\n\n return newEntry;\n}\n\nfunction insertAndSetRefCount(\n view: RCEntryList,\n newRow: Row,\n oldEntry: RCEntry,\n relationships: {[key: string]: Format},\n compareRows: Comparator,\n): void {\n const {pos, found} = binarySearch(view, newRow, compareRows);\n\n let deleteCount = 0;\n let rc = 1;\n if (found) {\n deleteCount = 1;\n const oldEntry = view[pos];\n rc = oldEntry[refCountSymbol] + 1;\n oldEntry[refCountSymbol] = 0;\n }\n\n const newEntry = makeEntryPreserveRelationships(\n newRow,\n oldEntry,\n relationships,\n rc,\n );\n\n view.splice(pos, deleteCount, newEntry);\n}\n\nfunction removeAndUpdateRefCount(\n view: RCEntryList,\n row: Row,\n compareRows: Comparator,\n): RCEntry {\n const {pos, found} = binarySearch(view, row, compareRows);\n assert(found, 'node does not exist');\n const oldEntry = view[pos];\n const rc = oldEntry[refCountSymbol];\n if (rc === 1) {\n view.splice(pos, 1);\n }\n oldEntry[refCountSymbol]--;\n\n return oldEntry;\n}\n\n// TODO: Do not return an object. It puts unnecessary pressure on the GC.\nfunction binarySearch(view: RCEntryList, target: Row, comparator: Comparator) {\n let low = 0;\n let high = view.length - 1;\n while (low <= high) {\n const mid = (low + high) >>> 1;\n const comparison = comparator(view[mid] as Row, target as Row);\n if (comparison < 0) {\n low = mid + 1;\n } else if (comparison > 0) {\n high = mid - 1;\n } else {\n return {pos: mid, found: true};\n }\n }\n return {pos: low, found: false};\n}\n\nfunction makeEntryPreserveRelationships(\n newRow: Row,\n oldEntry: RCEntry,\n relationships: {[key: string]: Format},\n rc: number,\n): RCEntry {\n const entry = makeNewEntryWithRefCount(newRow, rc);\n for (const relationship in relationships) {\n assert(!(relationship in newRow), 'Relationship already exists');\n entry[relationship] = oldEntry[relationship];\n }\n return entry;\n}\n\nfunction getChildEntryList(\n parentEntry: Entry,\n relationship: string,\n): RCEntryList {\n const view = parentEntry[relationship];\n assertArray(view);\n return view as RCEntryList;\n}\n\nfunction assertRCEntry(v: unknown): asserts v is RCEntry {\n assertNumber((v as Partial<RCEntry>)[refCountSymbol]);\n}\n\nfunction getSingularEntry(parentEntry: Entry, relationship: string): RCEntry {\n const e = parentEntry[relationship];\n assertNumber((e as Partial<RCEntry>)[refCountSymbol]);\n return e as RCEntry;\n}\n\nfunction makeNewEntryWithRefCount(row: Row, rc: number): RCEntry {\n return {...row, [refCountSymbol]: rc};\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,SAAS,OACd,GACA,MAA+B,oBACpB;AACX,MAAI,CAAC,GAAG;AACN,UAAM,IAAI,MAAM,OAAO,QAAQ,WAAW,MAAM,IAAI,CAAC;AAAA,EACvD;AACF;AAEO,SAAS,aAAa,GAAiC;AAC5D,aAAW,GAAG,QAAQ;AACxB;AAEO,SAAS,aAAa,GAAiC;AAC5D,aAAW,GAAG,QAAQ;AACxB;AAEO,SAAS,cAAc,GAAkC;AAC9D,aAAW,GAAG,SAAS;AACzB;AAEA,SAAS,WAAW,GAAY,GAAW;AACzC,MAAI,OAAO,MAAM,G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EAC7C;AACA,SAAO;AACT;AAEA,SAAS,kBACP,aACA,cACa;AACb,QAAM,OAAO,YAAY,YAAY;AACrC,cAAY,IAAI;AAChB,SAAO;AACT;AAEA,SAAS,cAAc,GAAkC;AACvD,eAAc,EAAuB,cAAc,CAAC;AACtD;AAEA,SAAS,iBAAiB,aAAoB,cAA+B;AAC3E,QAAM,IAAI,YAAY,YAAY;AAClC,eAAc,EAAuB,cAAc,CAAC;AACpD,SAAO;AACT;AAEA,SAAS,yBAAyB,KAAU,IAAqB;AAC/D,SAAO,EAAC,GAAG,KAAK,CAAC,cAAc,GAAG,GAAE;AACtC;",
|
|
6
6
|
"names": ["node", "relationship", "oldEntry"]
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
compareTTL,
|
|
4
4
|
hasOwn,
|
|
5
5
|
parseTTL
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2B2QE5AT.js";
|
|
7
7
|
import {
|
|
8
8
|
applyChange,
|
|
9
9
|
assert,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
throwInvalidType,
|
|
22
22
|
unreachable,
|
|
23
23
|
valuesEqual
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-2NCGIK6G.js";
|
|
25
25
|
import {
|
|
26
26
|
__export,
|
|
27
27
|
__reExport
|
|
@@ -7154,7 +7154,7 @@ var ReplicacheImpl = class {
|
|
|
7154
7154
|
/** The URL to use when doing a push request. */
|
|
7155
7155
|
pushURL;
|
|
7156
7156
|
/** The authorization token used when doing a push request. */
|
|
7157
|
-
auth;
|
|
7157
|
+
#auth;
|
|
7158
7158
|
/** The name of the Replicache database. Populated by {@link ReplicacheOptions#name}. */
|
|
7159
7159
|
name;
|
|
7160
7160
|
#subscriptions;
|
|
@@ -7173,6 +7173,15 @@ var ReplicacheImpl = class {
|
|
|
7173
7173
|
get idbName() {
|
|
7174
7174
|
return makeIDBName(this.name, this.schemaVersion);
|
|
7175
7175
|
}
|
|
7176
|
+
set auth(auth) {
|
|
7177
|
+
if (this.#zero) {
|
|
7178
|
+
this.#zero.auth = auth;
|
|
7179
|
+
}
|
|
7180
|
+
this.#auth = auth;
|
|
7181
|
+
}
|
|
7182
|
+
get auth() {
|
|
7183
|
+
return this.#auth;
|
|
7184
|
+
}
|
|
7176
7185
|
/** The schema version of the data understood by this application. */
|
|
7177
7186
|
schemaVersion;
|
|
7178
7187
|
get #idbDatabase() {
|
|
@@ -7334,7 +7343,7 @@ var ReplicacheImpl = class {
|
|
|
7334
7343
|
}
|
|
7335
7344
|
} = implOptions;
|
|
7336
7345
|
this.#zero = implOptions.zero;
|
|
7337
|
-
this
|
|
7346
|
+
this.#auth = auth ?? "";
|
|
7338
7347
|
this.pullURL = pullURL;
|
|
7339
7348
|
this.pushURL = pushURL;
|
|
7340
7349
|
this.name = name;
|
|
@@ -10128,6 +10137,8 @@ var Take = class {
|
|
|
10128
10137
|
#limit;
|
|
10129
10138
|
#partitionKey;
|
|
10130
10139
|
#partitionKeyComparator;
|
|
10140
|
+
// Fetch overlay needed for some split push cases.
|
|
10141
|
+
#rowHiddenFromFetch;
|
|
10131
10142
|
#output = throwOutput;
|
|
10132
10143
|
constructor(input, storage, limit, partitionKey) {
|
|
10133
10144
|
assert(limit >= 0);
|
|
@@ -10163,6 +10174,12 @@ var Take = class {
|
|
|
10163
10174
|
if (this.getSchema().compareRows(takeState.bound, inputNode.row) < 0) {
|
|
10164
10175
|
return;
|
|
10165
10176
|
}
|
|
10177
|
+
if (this.#rowHiddenFromFetch && this.getSchema().compareRows(
|
|
10178
|
+
this.#rowHiddenFromFetch,
|
|
10179
|
+
inputNode.row
|
|
10180
|
+
) === 0) {
|
|
10181
|
+
continue;
|
|
10182
|
+
}
|
|
10166
10183
|
yield inputNode;
|
|
10167
10184
|
}
|
|
10168
10185
|
return;
|
|
@@ -10305,14 +10322,16 @@ var Take = class {
|
|
|
10305
10322
|
type: "remove",
|
|
10306
10323
|
node: boundNode
|
|
10307
10324
|
};
|
|
10308
|
-
this.#output.push(change);
|
|
10309
10325
|
this.#setTakeState(
|
|
10310
10326
|
takeStateKey,
|
|
10311
10327
|
takeState.size,
|
|
10312
10328
|
beforeBoundNode === void 0 || compareRows(change.node.row, beforeBoundNode.row) > 0 ? change.node.row : beforeBoundNode.row,
|
|
10313
10329
|
maxBound
|
|
10314
10330
|
);
|
|
10315
|
-
this.#
|
|
10331
|
+
this.#withRowHiddenFromFetch(change.node.row, () => {
|
|
10332
|
+
this.#output.push(removeChange);
|
|
10333
|
+
});
|
|
10334
|
+
this.#output.push(change);
|
|
10316
10335
|
} else if (change.type === "remove") {
|
|
10317
10336
|
if (takeState.bound === void 0) {
|
|
10318
10337
|
return;
|
|
@@ -10483,19 +10502,21 @@ var Take = class {
|
|
|
10483
10502
|
}),
|
|
10484
10503
|
2
|
|
10485
10504
|
);
|
|
10486
|
-
this.#output.push({
|
|
10487
|
-
type: "add",
|
|
10488
|
-
node: change.node
|
|
10489
|
-
});
|
|
10490
10505
|
this.#setTakeState(
|
|
10491
10506
|
takeStateKey,
|
|
10492
10507
|
takeState.size,
|
|
10493
10508
|
newBoundNode.row,
|
|
10494
10509
|
maxBound
|
|
10495
10510
|
);
|
|
10511
|
+
this.#withRowHiddenFromFetch(change.node.row, () => {
|
|
10512
|
+
this.#output.push({
|
|
10513
|
+
type: "remove",
|
|
10514
|
+
node: oldBoundNode
|
|
10515
|
+
});
|
|
10516
|
+
});
|
|
10496
10517
|
this.#output.push({
|
|
10497
|
-
type: "
|
|
10498
|
-
node:
|
|
10518
|
+
type: "add",
|
|
10519
|
+
node: change.node
|
|
10499
10520
|
});
|
|
10500
10521
|
return;
|
|
10501
10522
|
}
|
|
@@ -10539,6 +10560,14 @@ var Take = class {
|
|
|
10539
10560
|
}
|
|
10540
10561
|
unreachable();
|
|
10541
10562
|
}
|
|
10563
|
+
#withRowHiddenFromFetch(row, fn) {
|
|
10564
|
+
this.#rowHiddenFromFetch = row;
|
|
10565
|
+
try {
|
|
10566
|
+
fn();
|
|
10567
|
+
} finally {
|
|
10568
|
+
this.#rowHiddenFromFetch = void 0;
|
|
10569
|
+
}
|
|
10570
|
+
}
|
|
10542
10571
|
#setTakeState(takeStateKey, size, bound, maxBound) {
|
|
10543
10572
|
this.#storage.set(takeStateKey, {
|
|
10544
10573
|
size,
|
|
@@ -10804,7 +10833,7 @@ function transformFilters(filters) {
|
|
|
10804
10833
|
|
|
10805
10834
|
// ../zql/src/builder/builder.ts
|
|
10806
10835
|
function buildPipeline(ast, delegate) {
|
|
10807
|
-
return buildPipelineInternal(ast, delegate, "");
|
|
10836
|
+
return buildPipelineInternal(delegate.mapAst(ast), delegate, "");
|
|
10808
10837
|
}
|
|
10809
10838
|
function buildPipelineInternal(ast, delegate, name, partitionKey) {
|
|
10810
10839
|
const source = delegate.getSource(ast.table);
|
|
@@ -12406,7 +12435,7 @@ var CRUD = "crud";
|
|
|
12406
12435
|
var Custom = "custom";
|
|
12407
12436
|
|
|
12408
12437
|
// ../zero-protocol/src/protocol-version.ts
|
|
12409
|
-
var PROTOCOL_VERSION =
|
|
12438
|
+
var PROTOCOL_VERSION = 8;
|
|
12410
12439
|
var MIN_SERVER_SUPPORTED_SYNC_PROTOCOL = 6;
|
|
12411
12440
|
assert(MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION);
|
|
12412
12441
|
|
|
@@ -13813,6 +13842,9 @@ var ZeroContext = class {
|
|
|
13813
13842
|
);
|
|
13814
13843
|
}
|
|
13815
13844
|
}
|
|
13845
|
+
mapAst(ast) {
|
|
13846
|
+
return ast;
|
|
13847
|
+
}
|
|
13816
13848
|
createStorage() {
|
|
13817
13849
|
return new MemoryStorage();
|
|
13818
13850
|
}
|
|
@@ -14085,23 +14117,22 @@ var TransactionImpl = class {
|
|
|
14085
14117
|
this.clientID = repTx.clientID;
|
|
14086
14118
|
this.mutationID = repTx.mutationID;
|
|
14087
14119
|
this.reason = repTx.reason === "initial" ? "optimistic" : "rebase";
|
|
14120
|
+
const txData = must(
|
|
14121
|
+
castedRepTx[zeroData],
|
|
14122
|
+
"zero was not set on replicache internal options!"
|
|
14123
|
+
);
|
|
14088
14124
|
this.mutate = makeSchemaCRUD(
|
|
14089
14125
|
schema,
|
|
14090
14126
|
repTx,
|
|
14091
|
-
|
|
14092
|
-
castedRepTx[zeroData],
|
|
14093
|
-
"zero was not set on replicache internal options!"
|
|
14094
|
-
)
|
|
14127
|
+
txData.ivmSources
|
|
14095
14128
|
);
|
|
14096
14129
|
this.query = makeSchemaQuery(
|
|
14097
14130
|
lc,
|
|
14098
14131
|
schema,
|
|
14099
|
-
|
|
14100
|
-
castedRepTx[zeroData],
|
|
14101
|
-
"zero was not set on replicache internal options!"
|
|
14102
|
-
),
|
|
14132
|
+
txData.ivmSources,
|
|
14103
14133
|
slowMaterializeThreshold
|
|
14104
14134
|
);
|
|
14135
|
+
this.token = txData.token;
|
|
14105
14136
|
}
|
|
14106
14137
|
clientID;
|
|
14107
14138
|
mutationID;
|
|
@@ -14109,6 +14140,7 @@ var TransactionImpl = class {
|
|
|
14109
14140
|
location = "client";
|
|
14110
14141
|
mutate;
|
|
14111
14142
|
query;
|
|
14143
|
+
token;
|
|
14112
14144
|
};
|
|
14113
14145
|
function makeReplicacheMutator(lc, mutator, schema, slowMaterializeThreshold) {
|
|
14114
14146
|
return (repTx, args) => {
|
|
@@ -14484,7 +14516,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
14484
14516
|
}
|
|
14485
14517
|
|
|
14486
14518
|
// ../zero-client/src/client/version.ts
|
|
14487
|
-
var version2 = "0.18.
|
|
14519
|
+
var version2 = "0.18.2025032000";
|
|
14488
14520
|
|
|
14489
14521
|
// ../zero-client/src/client/log-options.ts
|
|
14490
14522
|
var LevelFilterLogSink = class {
|
|
@@ -15413,11 +15445,19 @@ var ZeroRep = class {
|
|
|
15413
15445
|
#ivmMain;
|
|
15414
15446
|
#customMutatorsEnabled;
|
|
15415
15447
|
#store;
|
|
15448
|
+
#auth;
|
|
15416
15449
|
constructor(context, ivmMain, customMutatorsEnabled) {
|
|
15417
15450
|
this.#context = context;
|
|
15418
15451
|
this.#ivmMain = ivmMain;
|
|
15419
15452
|
this.#customMutatorsEnabled = customMutatorsEnabled;
|
|
15420
15453
|
}
|
|
15454
|
+
set auth(auth) {
|
|
15455
|
+
if (auth === "") {
|
|
15456
|
+
this.#auth = void 0;
|
|
15457
|
+
} else {
|
|
15458
|
+
this.#auth = auth;
|
|
15459
|
+
}
|
|
15460
|
+
}
|
|
15421
15461
|
async init(hash2, store) {
|
|
15422
15462
|
const diffs = [];
|
|
15423
15463
|
await withRead(store, async (dagRead) => {
|
|
@@ -15440,11 +15480,10 @@ var ZeroRep = class {
|
|
|
15440
15480
|
if (!this.#customMutatorsEnabled) {
|
|
15441
15481
|
return;
|
|
15442
15482
|
}
|
|
15443
|
-
return this.#ivmMain.forkToHead(
|
|
15444
|
-
|
|
15445
|
-
|
|
15446
|
-
|
|
15447
|
-
);
|
|
15483
|
+
return this.#ivmMain.forkToHead(must(this.#store), desiredHead, readOptions).then((branch) => ({
|
|
15484
|
+
ivmSources: branch,
|
|
15485
|
+
token: this.#auth
|
|
15486
|
+
}));
|
|
15448
15487
|
};
|
|
15449
15488
|
advance = (expectedHash, newHash, diffs) => {
|
|
15450
15489
|
this.#context.processChanges(expectedHash, newHash, diffs);
|
|
@@ -16223,7 +16262,10 @@ var Zero = class {
|
|
|
16223
16262
|
ws.addEventListener("close", this.#onClose);
|
|
16224
16263
|
this.#socket = ws;
|
|
16225
16264
|
this.#socketResolver.resolve(ws);
|
|
16226
|
-
getBrowserGlobal("window")?.addEventListener(
|
|
16265
|
+
getBrowserGlobal("window")?.addEventListener?.(
|
|
16266
|
+
"pagehide",
|
|
16267
|
+
this.#onPageHide
|
|
16268
|
+
);
|
|
16227
16269
|
try {
|
|
16228
16270
|
l.debug?.("Waiting for connection to be acknowledged");
|
|
16229
16271
|
await this.#connectResolver.promise;
|
|
@@ -16293,7 +16335,7 @@ var Zero = class {
|
|
|
16293
16335
|
this.#socket = void 0;
|
|
16294
16336
|
this.#lastMutationIDSent = NULL_LAST_MUTATION_ID_SENT;
|
|
16295
16337
|
this.#pokeHandler.handleDisconnect();
|
|
16296
|
-
getBrowserGlobal("window")?.removeEventListener(
|
|
16338
|
+
getBrowserGlobal("window")?.removeEventListener?.(
|
|
16297
16339
|
"pagehide",
|
|
16298
16340
|
this.#onPageHide
|
|
16299
16341
|
);
|
|
@@ -16789,4 +16831,4 @@ export {
|
|
|
16789
16831
|
escapeLike,
|
|
16790
16832
|
Zero
|
|
16791
16833
|
};
|
|
16792
|
-
//# sourceMappingURL=chunk-
|
|
16834
|
+
//# sourceMappingURL=chunk-6AOMML7A.js.map
|