@rocicorp/zero 0.25.0-canary.23 → 0.25.0-canary.24
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/analyze-query/src/run-ast.d.ts +1 -1
- package/out/analyze-query/src/run-ast.d.ts.map +1 -1
- package/out/analyze-query/src/run-ast.js +7 -1
- package/out/analyze-query/src/run-ast.js.map +1 -1
- package/out/otel/src/log-options.d.ts +1 -1
- package/out/otel/src/log-options.d.ts.map +1 -1
- package/out/otel/src/log-options.js +0 -1
- package/out/otel/src/log-options.js.map +1 -1
- package/out/shared/src/options-types.d.ts +113 -0
- package/out/shared/src/options-types.d.ts.map +1 -0
- package/out/shared/src/options.d.ts +2 -111
- package/out/shared/src/options.d.ts.map +1 -1
- package/out/shared/src/options.js.map +1 -1
- package/out/zero/package.json.js +1 -1
- package/out/zero/src/pg.js +1 -2
- package/out/zero/src/server.js +1 -2
- package/out/zero/src/zero-cache-dev.js +11 -5
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero/src/zero.js +0 -2
- package/out/zero/src/zero.js.map +1 -1
- package/out/zero-cache/src/auth/read-authorizer.js +1 -1
- package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
- package/out/zero-cache/src/auth/write-authorizer.js +1 -1
- 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 +5 -3
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +6 -3
- package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
- package/out/zero-cache/src/scripts/permissions.d.ts.map +1 -1
- package/out/zero-cache/src/scripts/permissions.js +11 -13
- package/out/zero-cache/src/scripts/permissions.js.map +1 -1
- package/out/zero-client/src/client/crud.d.ts +3 -2
- package/out/zero-client/src/client/crud.d.ts.map +1 -1
- package/out/zero-client/src/client/crud.js +7 -3
- package/out/zero-client/src/client/crud.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +3 -2
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/custom.js +2 -2
- package/out/zero-client/src/client/custom.js.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.d.ts +1 -1
- package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
- package/out/zero-client/src/client/make-mutate-property.js +2 -2
- package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
- package/out/zero-client/src/client/mutator-proxy.js +6 -7
- package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts +14 -3
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +19 -6
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/mod.d.ts +3 -4
- package/out/zero-client/src/mod.d.ts.map +1 -1
- package/out/zero-schema/src/compiled-permissions.d.ts +22 -2
- package/out/zero-schema/src/compiled-permissions.d.ts.map +1 -1
- package/out/zero-schema/src/compiled-permissions.js +7 -6
- package/out/zero-schema/src/compiled-permissions.js.map +1 -1
- package/out/zero-schema/src/permissions.d.ts.map +1 -1
- package/out/zero-schema/src/permissions.js.map +1 -1
- package/out/zero-schema/src/schema-config.d.ts +0 -5
- package/out/zero-schema/src/schema-config.d.ts.map +1 -1
- package/out/zero-schema/src/schema-config.js +1 -1
- package/out/zero-schema/src/schema-config.js.map +1 -1
- package/out/zero-server/src/custom.d.ts +5 -14
- package/out/zero-server/src/custom.d.ts.map +1 -1
- package/out/zero-server/src/custom.js +8 -18
- package/out/zero-server/src/custom.js.map +1 -1
- package/out/zql/src/mutate/crud.d.ts +3 -26
- package/out/zql/src/mutate/crud.d.ts.map +1 -1
- package/out/zql/src/mutate/crud.js +14 -26
- package/out/zql/src/mutate/crud.js.map +1 -1
- package/out/zql/src/mutate/custom.d.ts +7 -8
- package/out/zql/src/mutate/custom.d.ts.map +1 -1
- package/out/zql/src/mutate/custom.js.map +1 -1
- package/out/zql/src/planner/planner-join.d.ts.map +1 -1
- package/out/zql/src/planner/planner-join.js +3 -1
- package/out/zql/src/planner/planner-join.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sources":["../../../../../zero-cache/src/scripts/permissions.ts"],"sourcesContent":["import {existsSync} from 'node:fs';\nimport {basename, dirname, join, relative, resolve, sep} from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {tsImport} from 'tsx/esm/api';\nimport {logOptions} from '../../../otel/src/log-options.ts';\nimport {colorConsole} from '../../../shared/src/logging.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport {\n permissionsConfigSchema,\n type PermissionsConfig,\n} from '../../../zero-schema/src/compiled-permissions.ts';\nimport {isSchemaConfig} from '../../../zero-schema/src/schema-config.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {appOptions, shardOptions, zeroOptions} from '../config/zero-config.ts';\n\nexport const deployPermissionsOptions = {\n schema: {\n path: {\n type: v.string().default('schema.ts'),\n desc: [
|
|
1
|
+
{"version":3,"file":"permissions.js","sources":["../../../../../zero-cache/src/scripts/permissions.ts"],"sourcesContent":["import {existsSync} from 'node:fs';\nimport {basename, dirname, join, relative, resolve, sep} from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {tsImport} from 'tsx/esm/api';\nimport {logOptions} from '../../../otel/src/log-options.ts';\nimport {colorConsole} from '../../../shared/src/logging.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport {\n permissionsConfigSchema,\n type PermissionsConfig,\n} from '../../../zero-schema/src/compiled-permissions.ts';\nimport {isSchemaConfig} from '../../../zero-schema/src/schema-config.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {appOptions, shardOptions, zeroOptions} from '../config/zero-config.ts';\n\nexport const deployPermissionsOptions = {\n schema: {\n path: {\n type: v.string().default('schema.ts'),\n desc: ['Relative path to the file containing the schema definition.'],\n alias: 'p',\n },\n },\n\n upstream: {\n db: {\n type: v.string().optional(),\n desc: [\n `The upstream Postgres database to deploy permissions to.`,\n `This is ignored if an {bold output-file} is specified.`,\n ],\n },\n\n type: zeroOptions.upstream.type,\n },\n\n app: {id: appOptions.id},\n\n shard: shardOptions,\n\n log: logOptions,\n\n output: {\n file: {\n type: v.string().optional(),\n desc: [\n `Outputs the permissions to a file with the requested {bold output-format}.`,\n ],\n },\n\n format: {\n type: v.literalUnion('sql', 'json', 'pretty').default('sql'),\n desc: [\n `The desired format of the output file.`,\n ``,\n `A {bold sql} file can be executed via \"psql -f <file.sql>\", or \"\\\\\\\\i <file.sql>\"`,\n `from within the psql console, or copied and pasted into a migration script.`,\n ``,\n `The {bold json} and {bold pretty} formats are available for non-pg backends`,\n `and general debugging.`,\n ],\n },\n },\n\n force: {\n type: v.boolean().default(false),\n desc: [`Deploy to upstream without validation. Use at your own risk.`],\n alias: 'f',\n },\n};\n\nexport async function loadSchemaAndPermissions(\n schemaPath: string,\n allowMissing: true,\n): Promise<{schema: Schema; permissions: PermissionsConfig} | undefined>;\nexport async function loadSchemaAndPermissions(\n schemaPath: string,\n allowMissing?: false,\n): Promise<{schema: Schema; permissions: PermissionsConfig}>;\nexport async function loadSchemaAndPermissions(\n schemaPath: string,\n allowMissing: boolean | undefined,\n): Promise<{schema: Schema; permissions: PermissionsConfig} | undefined> {\n const typeModuleErrorMessage = () =>\n `\\n\\nYou may need to add \\` \"type\": \"module\" \\` to the package.json file for ${schemaPath}.\\n`;\n\n colorConsole.info(`Loading schema from ${schemaPath}`);\n\n const dir = dirname(fileURLToPath(import.meta.url));\n const absoluteSchemaPath = resolve(schemaPath);\n const relativeDir = relative(dir, dirname(absoluteSchemaPath));\n let relativePath =\n relativeDir.length && relativeDir !== '.'\n ? join(relativeDir, basename(absoluteSchemaPath))\n : `.${sep}${basename(absoluteSchemaPath)}`;\n\n // tsImport doesn't expect to receive slashes in the Windows format when running\n // on Windows. They need to be converted to *nix format.\n relativePath = relativePath.replace(/\\\\/g, '/');\n\n if (!existsSync(absoluteSchemaPath)) {\n if (allowMissing) {\n return undefined;\n }\n colorConsole.error(`Schema file ${schemaPath} does not exist.`);\n process.exit(1);\n }\n\n let module;\n try {\n module = await tsImport(relativePath, import.meta.url);\n } catch (e) {\n colorConsole.error(\n `Failed to load zero schema from ${absoluteSchemaPath}` +\n typeModuleErrorMessage(),\n );\n throw e;\n }\n\n if (!isSchemaConfig(module)) {\n colorConsole.error(\n `Schema file ${schemaPath} must export [schema].` +\n typeModuleErrorMessage(),\n );\n process.exit(1);\n }\n try {\n const schemaConfig = module;\n const perms =\n await (schemaConfig.permissions as unknown as Promise<unknown>);\n const {schema} = schemaConfig;\n\n if (perms) {\n colorConsole.warn?.(\n 'Permissions are deprecated and will be removed in an upcoming release. See: https://zero.rocicorp.dev/docs/auth.',\n );\n }\n\n return {\n schema,\n permissions: v.parse(perms ?? {}, permissionsConfigSchema),\n };\n } catch (e) {\n colorConsole.error(`Failed to parse Permissions object`);\n throw e;\n }\n}\n"],"names":["v.string","v.literalUnion","v.boolean","v.parse"],"mappings":";;;;;;;;;;;AAeO,MAAM,2BAA2B;AAAA,EACtC,QAAQ;AAAA,IACN,MAAM;AAAA,MACJ,MAAMA,OAAE,EAAS,QAAQ,WAAW;AAAA,MACpC,MAAM,CAAC,6DAA6D;AAAA,MACpE,OAAO;AAAA,IAAA;AAAA,EACT;AAAA,EAGF,UAAU;AAAA,IACR,IAAI;AAAA,MACF,MAAMA,OAAE,EAAS,SAAA;AAAA,MACjB,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,MAAA;AAAA,IACF;AAAA,IAGF,MAAM,YAAY,SAAS;AAAA,EAAA;AAAA,EAG7B,KAAK,EAAC,IAAI,WAAW,GAAA;AAAA,EAErB,OAAO;AAAA,EAEP,KAAK;AAAA,EAEL,QAAQ;AAAA,IACN,MAAM;AAAA,MACJ,MAAMA,OAAE,E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ACX,eAAe,UAAU,2BACvB,uBAAA;AAAA,IAAuB;AAE3B,YAAQ,KAAK,CAAC;AAAA,EAChB;AACA,MAAI;AACF,UAAM,eAAe;AACrB,UAAM,QACJ,MAAO,aAAa;AACtB,UAAM,EAAC,WAAU;AAEjB,QAAI,OAAO;AACT,mBAAa;AAAA,QACX;AAAA,MAAA;AAAA,IAEJ;AAEA,WAAO;AAAA,MACL;AAAA,MACA,aAAaC,MAAQ,SAAS,CAAA,GAAI,uBAAuB;AAAA,IAAA;AAAA,EAE7D,SAAS,GAAG;AACV,iBAAa,MAAM,oCAAoC;AACvD,UAAM;AAAA,EACR;AACF;"}
|
|
@@ -13,7 +13,7 @@ type ZeroCRUDMutate = {
|
|
|
13
13
|
[CRUD_MUTATION_NAME]: CRUDMutate;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* This is the zero.
|
|
16
|
+
* This is the zero.mutateBatch function part representing the CRUD operations. If the
|
|
17
17
|
* tables are `issue` and `label`, then this object will have `issue` and
|
|
18
18
|
* `label` properties.
|
|
19
19
|
*
|
|
@@ -22,7 +22,8 @@ type ZeroCRUDMutate = {
|
|
|
22
22
|
* @param mutate - The object to use as the mutate object. Properties for each
|
|
23
23
|
* table will be assigned to this object.
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function makeCRUDMutateBatch<const S extends Schema>(schema: S, repMutate: ZeroCRUDMutate): BatchMutator<S>;
|
|
26
|
+
export declare function addTableCRUDProperties<TSchema extends Schema>(schema: TSchema, mutate: object, repMutate: ZeroCRUDMutate): void;
|
|
26
27
|
/**
|
|
27
28
|
* Creates the `{insert, upsert, update, delete}` object for use inside a
|
|
28
29
|
* batch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/crud.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAC/D,OAAO,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AC7D,SAAS,CAAC;AAEhB,KAAK,cAAc,GAAG;IACpB,CAAC,kBAAkB,CAAC,EAAE,UAAU,CAAC;CAClC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACxD,MAAM,EAAE,CAAC,EACT,SAAS,EAAE,cAAc,GACxB,YAAY,CAAC,CAAC,CAAC,CAoBjB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,cAAc,GACxB,IAAI,CASN;AAmDD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,WAAW,EACvD,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EAAE,GACZ,YAAY,CAAC,CAAC,CAAC,CA4CjB;AAED,MAAM,MAAM,QAAQ,CAAC,EAAE,SAAS,WAAW,IAAI,EAAE,GAAG;IAClD,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG,CACxB,EAAE,EAAE,gBAAgB,EACpB,OAAO,EAAE,eAAe,KACrB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,gBAAgB,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,eAAe,GAAG,SAAS,GACrC,YAAY,CAWd;AAMD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAU3D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promiseVoid } from "../../../shared/src/resolved-promises.js";
|
|
2
2
|
import { CRUD_MUTATION_NAME } from "../../../zero-protocol/src/push.js";
|
|
3
3
|
import * as crudImpl from "./crud-impl.js";
|
|
4
|
-
function
|
|
4
|
+
function makeCRUDMutateBatch(schema, repMutate) {
|
|
5
5
|
if (schema.enableLegacyMutators !== true) {
|
|
6
6
|
return void 0;
|
|
7
7
|
}
|
|
@@ -16,6 +16,10 @@ function makeCRUDMutate(schema, repMutate, mutate) {
|
|
|
16
16
|
await zeroCRUD({ ops });
|
|
17
17
|
return rv;
|
|
18
18
|
};
|
|
19
|
+
return mutateBatch;
|
|
20
|
+
}
|
|
21
|
+
function addTableCRUDProperties(schema, mutate, repMutate) {
|
|
22
|
+
const { [CRUD_MUTATION_NAME]: zeroCRUD } = repMutate;
|
|
19
23
|
for (const [name, tableSchema] of Object.entries(schema.tables)) {
|
|
20
24
|
mutate[name] = makeEntityCRUDMutate(
|
|
21
25
|
name,
|
|
@@ -23,7 +27,6 @@ function makeCRUDMutate(schema, repMutate, mutate) {
|
|
|
23
27
|
zeroCRUD
|
|
24
28
|
);
|
|
25
29
|
}
|
|
26
|
-
return mutateBatch;
|
|
27
30
|
}
|
|
28
31
|
function makeEntityCRUDMutate(tableName, primaryKey, zeroCRUD) {
|
|
29
32
|
return {
|
|
@@ -131,9 +134,10 @@ function makeCRUDMutator(schema) {
|
|
|
131
134
|
};
|
|
132
135
|
}
|
|
133
136
|
export {
|
|
137
|
+
addTableCRUDProperties,
|
|
134
138
|
makeBatchCRUDMutate,
|
|
135
139
|
makeCRUDExecutor,
|
|
136
|
-
|
|
140
|
+
makeCRUDMutateBatch,
|
|
137
141
|
makeCRUDMutator
|
|
138
142
|
};
|
|
139
143
|
//# sourceMappingURL=crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.js","sources":["../../../../../zero-client/src/client/crud.ts"],"sourcesContent":["import {promiseVoid} from '../../../shared/src/resolved-promises.ts';\nimport type {MaybePromise} from '../../../shared/src/types.ts';\nimport {\n CRUD_MUTATION_NAME,\n type CRUDMutationArg,\n type CRUDOp,\n type DeleteOp,\n type InsertOp,\n type UpdateOp,\n type UpsertOp,\n} from '../../../zero-protocol/src/push.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {
|
|
1
|
+
{"version":3,"file":"crud.js","sources":["../../../../../zero-client/src/client/crud.ts"],"sourcesContent":["import {promiseVoid} from '../../../shared/src/resolved-promises.ts';\nimport type {MaybePromise} from '../../../shared/src/types.ts';\nimport {\n CRUD_MUTATION_NAME,\n type CRUDMutationArg,\n type CRUDOp,\n type DeleteOp,\n type InsertOp,\n type UpdateOp,\n type UpsertOp,\n} from '../../../zero-protocol/src/push.ts';\nimport type {TableSchema} from '../../../zero-schema/src/table-schema.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {\n CRUDExecutor,\n DeleteID,\n InsertValue,\n TableMutator,\n UpdateValue,\n UpsertValue,\n} from '../../../zql/src/mutate/crud.ts';\nimport * as crudImpl from './crud-impl.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {MutatorDefs, WriteTransaction} from './replicache-types.ts';\n\nexport type DBMutator<S extends Schema> = S['enableLegacyMutators'] extends true\n ? {\n [K in keyof S['tables']]: TableMutator<S['tables'][K]>;\n }\n : {}; // {} is needed here for intersection type identity\n\nexport type BatchMutator<S extends Schema> =\n S['enableLegacyMutators'] extends true\n ? <R>(body: (m: DBMutator<S>) => MaybePromise<R>) => Promise<R>\n : undefined;\n\ntype ZeroCRUDMutate = {\n [CRUD_MUTATION_NAME]: CRUDMutate;\n};\n\n/**\n * This is the zero.mutateBatch function part representing the CRUD operations. If the\n * tables are `issue` and `label`, then this object will have `issue` and\n * `label` properties.\n *\n * @param schema - The schema defining the tables\n * @param repMutate - The replicache mutate object with the CRUD mutation\n * @param mutate - The object to use as the mutate object. Properties for each\n * table will be assigned to this object.\n */\nexport function makeCRUDMutateBatch<const S extends Schema>(\n schema: S,\n repMutate: ZeroCRUDMutate,\n): BatchMutator<S> {\n if (schema.enableLegacyMutators !== true) {\n return undefined as BatchMutator<S>;\n }\n\n const {[CRUD_MUTATION_NAME]: zeroCRUD} = repMutate;\n\n const mutateBatch = async <R>(body: (m: DBMutator<S>) => R): Promise<R> => {\n const ops: CRUDOp[] = [];\n const m = {} as Record<string, unknown>;\n for (const name of Object.keys(schema.tables)) {\n m[name] = makeBatchCRUDMutate(name, schema, ops);\n }\n\n const rv = await body(m as DBMutator<S>);\n await zeroCRUD({ops});\n return rv;\n };\n\n return mutateBatch as BatchMutator<S>;\n}\n\nexport function addTableCRUDProperties<TSchema extends Schema>(\n schema: TSchema,\n mutate: object,\n repMutate: ZeroCRUDMutate,\n): void {\n const {[CRUD_MUTATION_NAME]: zeroCRUD} = repMutate;\n for (const [name, tableSchema] of Object.entries(schema.tables)) {\n (mutate as Record<string, unknown>)[name] = makeEntityCRUDMutate(\n name,\n tableSchema.primaryKey,\n zeroCRUD,\n );\n }\n}\n\n/**\n * Creates the `{insert, upsert, update, delete}` object for use outside a\n * batch.\n */\nfunction makeEntityCRUDMutate<S extends TableSchema>(\n tableName: string,\n primaryKey: S['primaryKey'],\n zeroCRUD: CRUDMutate,\n): TableMutator<S> {\n return {\n insert: (value: InsertValue<S>) => {\n const op: InsertOp = {\n op: 'insert',\n tableName,\n primaryKey,\n value,\n };\n return zeroCRUD({ops: [op]});\n },\n upsert: (value: UpsertValue<S>) => {\n const op: UpsertOp = {\n op: 'upsert',\n tableName,\n primaryKey,\n value,\n };\n return zeroCRUD({ops: [op]});\n },\n update: (value: UpdateValue<S>) => {\n const op: UpdateOp = {\n op: 'update',\n tableName,\n primaryKey,\n value,\n };\n return zeroCRUD({ops: [op]});\n },\n delete: (id: DeleteID<S>) => {\n const op: DeleteOp = {\n op: 'delete',\n tableName,\n primaryKey,\n value: id,\n };\n return zeroCRUD({ops: [op]});\n },\n };\n}\n\n/**\n * Creates the `{insert, upsert, update, delete}` object for use inside a\n * batch.\n */\nexport function makeBatchCRUDMutate<S extends TableSchema>(\n tableName: string,\n schema: Schema,\n ops: CRUDOp[],\n): TableMutator<S> {\n const {primaryKey} = schema.tables[tableName];\n return {\n insert: (value: InsertValue<S>) => {\n const op: InsertOp = {\n op: 'insert',\n tableName,\n primaryKey,\n value,\n };\n ops.push(op);\n return promiseVoid;\n },\n upsert: (value: UpsertValue<S>) => {\n const op: UpsertOp = {\n op: 'upsert',\n tableName,\n primaryKey,\n value,\n };\n ops.push(op);\n return promiseVoid;\n },\n update: (value: UpdateValue<S>) => {\n const op: UpdateOp = {\n op: 'update',\n tableName,\n primaryKey,\n value,\n };\n ops.push(op);\n return promiseVoid;\n },\n delete: (id: DeleteID<S>) => {\n const op: DeleteOp = {\n op: 'delete',\n tableName,\n primaryKey,\n value: id,\n };\n ops.push(op);\n return promiseVoid;\n },\n };\n}\n\nexport type WithCRUD<MD extends MutatorDefs> = MD & {\n [CRUD_MUTATION_NAME]: CRUDMutator;\n};\n\nexport type CRUDMutate = (crudArg: CRUDMutationArg) => Promise<void>;\n\nexport type CRUDMutator = (\n tx: WriteTransaction,\n crudArg: CRUDMutationArg,\n) => Promise<void>;\n\nexport function makeCRUDExecutor(\n tx: WriteTransaction,\n schema: Schema,\n ivmBranch: IVMSourceBranch | undefined,\n): CRUDExecutor {\n return (tableName, kind, value) => {\n const {primaryKey} = schema.tables[tableName];\n return crudImpl[kind](\n tx,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n {op: kind, tableName, primaryKey, value} as any,\n schema,\n ivmBranch,\n );\n };\n}\n\n// Zero crud mutators cannot function at the same\n// time as custom mutators as the rebase of crud mutators will not\n// update the IVM branch. That's ok, we're removing crud mutators\n// in favor of custom mutators.\nexport function makeCRUDMutator(schema: Schema): CRUDMutator {\n return async (\n tx: WriteTransaction,\n crudArg: CRUDMutationArg,\n ): Promise<void> => {\n const executor = makeCRUDExecutor(tx, schema, undefined);\n for (const op of crudArg.ops) {\n await executor(op.tableName, op.op, op.value);\n }\n };\n}\n"],"names":[],"mappings":";;;AAkDO,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BAAgB,QAA6B;AAC3D,SAAO,OACL,IACA,YACkB;AAClB,UAAM,WAAW,iBAAiB,IAAI,QAAQ,MAAS;AACvD,eAAW,MAAM,QAAQ,KAAK;AAC5B,YAAM,SAAS,GAAG,WAAW,GAAG,IAAI,GAAG,KAAK;AAAA,IAC9C;AAAA,EACF;AACF;"}
|
|
@@ -3,7 +3,8 @@ import type { ZeroTxData } from '../../../replicache/src/replicache-options.ts';
|
|
|
3
3
|
import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
|
|
4
4
|
import type { DefaultSchema } from '../../../zero-types/src/default-types.ts';
|
|
5
5
|
import type { Schema } from '../../../zero-types/src/schema.ts';
|
|
6
|
-
import
|
|
6
|
+
import { type TransactionMutate } from '../../../zql/src/mutate/crud.ts';
|
|
7
|
+
import type { ClientTransaction, Transaction } from '../../../zql/src/mutate/custom.ts';
|
|
7
8
|
import { type HumanReadable, type Query, type RunOptions } from '../../../zql/src/query/query.ts';
|
|
8
9
|
import type { SchemaQuery } from '../../../zql/src/query/schema-query.ts';
|
|
9
10
|
import type { ClientID } from '../types/client-state.ts';
|
|
@@ -54,7 +55,7 @@ export type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (t
|
|
|
54
55
|
export declare class TransactionImpl<TSchema extends Schema = DefaultSchema> implements ClientTransaction<TSchema> {
|
|
55
56
|
#private;
|
|
56
57
|
readonly location = "client";
|
|
57
|
-
readonly mutate:
|
|
58
|
+
readonly mutate: TransactionMutate<TSchema>;
|
|
58
59
|
/**
|
|
59
60
|
* @deprecated Use {@linkcode createBuilder} with `tx.run(zql.table.where(...))` instead.
|
|
60
61
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,+CAA+C,CA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C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,UAAU,CAMjE;AAED,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,EAChB,mBAAmB,EACnB,OAAO,EAEP,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,mBAAmB,CAAC,EAClD,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,OAAO,GACf,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAQrE"}
|
|
@@ -2,7 +2,7 @@ import { zeroData } from "../../../replicache/src/transactions.js";
|
|
|
2
2
|
import { assert } from "../../../shared/src/asserts.js";
|
|
3
3
|
import { must } from "../../../shared/src/must.js";
|
|
4
4
|
import { emptyFunction } from "../../../shared/src/sentinels.js";
|
|
5
|
-
import {
|
|
5
|
+
import { makeTransactionMutate } from "../../../zql/src/mutate/crud.js";
|
|
6
6
|
import { createRunnableBuilder } from "../../../zql/src/query/create-builder.js";
|
|
7
7
|
import "../../../zero-protocol/src/ast.js";
|
|
8
8
|
import { ZeroContext } from "./context.js";
|
|
@@ -22,7 +22,7 @@ class TransactionImpl {
|
|
|
22
22
|
const ivmBranch = txData.ivmSources;
|
|
23
23
|
this.#repTx = repTx;
|
|
24
24
|
const executor = makeCRUDExecutor(repTx, schema, ivmBranch);
|
|
25
|
-
this.mutate =
|
|
25
|
+
this.mutate = makeTransactionMutate(schema, executor);
|
|
26
26
|
const zeroContext = newZeroContext(
|
|
27
27
|
lc,
|
|
28
28
|
txData.ivmSources
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {
|
|
1
|
+
{"version":3,"file":"custom.js","sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n makeTransactionMutate,\n type TransactionMutate,\n} from '../../../zql/src/mutate/crud.ts';\nimport type {\n ClientTransaction,\n Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport {createRunnableBuilder} from '../../../zql/src/query/create-builder.ts';\nimport {\n type HumanReadable,\n type Query,\n type RunOptions,\n} from '../../../zql/src/query/query.ts';\nimport type {SchemaQuery} from '../../../zql/src/query/schema-query.ts';\nimport type {ClientID} from '../types/client-state.ts';\nimport {ZeroContext} from './context.ts';\nimport {makeCRUDExecutor} from './crud.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {WriteTransaction} from './replicache-types.ts';\n\n/**\n * The shape which a user's custom mutator definitions must conform to.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type CustomMutatorDefs = {\n // oxlint-disable-next-line no-explicit-any\n [namespaceOrKey: string]: CustomMutatorImpl<any> | CustomMutatorDefs;\n};\n\nexport type MutatorResultDetails =\n | {\n readonly type: 'success';\n }\n | {\n readonly type: 'error';\n readonly error:\n | {\n readonly type: 'app';\n readonly message: string;\n readonly details: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'zero';\n readonly message: string;\n };\n };\n\nexport type MutatorResultSuccessDetails = Extract<\n MutatorResultDetails,\n {type: 'success'}\n>;\nexport type MutatorResultErrorDetails = Extract<\n MutatorResultDetails,\n {type: 'error'}\n>;\n\nexport type MutatorResult = {\n client: Promise<MutatorResultDetails & {}>;\n server: Promise<MutatorResultDetails & {}>;\n} & {};\n\nexport type CustomMutatorImpl<\n S extends Schema,\n TWrappedTransaction = unknown,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs = any,\n Context = unknown,\n> = (\n tx: Transaction<S, TWrappedTransaction>,\n // TODO: many args. See commit: 52657c2f934b4a458d628ea77e56ce92b61eb3c6 which did have many args.\n // The issue being that it will be a protocol change to support varargs.\n args: TArgs,\n ctx: Context,\n) => Promise<void>;\n\n/**\n * The shape exposed on the `Zero.mutate` instance.\n * The signature of a custom mutator takes a `transaction` as its first arg\n * but the user does not provide this arg when calling the mutator.\n *\n * This utility strips the `tx` arg from the user's custom mutator signatures.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type MakeCustomMutatorInterfaces<\n S extends Schema,\n MD extends CustomMutatorDefs,\n TContext,\n> = {\n readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<void>\n ? (...args: Args) => MutatorResult\n : MD[NamespaceOrName] extends CustomMutatorDefs\n ? MakeCustomMutatorInterfaces<S, MD[NamespaceOrName], TContext>\n : never;\n};\n\nexport type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (\n tx: ClientTransaction<TSchema>,\n ...args: infer Args\n) => Promise<void>\n ? (...args: Args) => MutatorResult\n : never;\n\nexport class TransactionImpl<TSchema extends Schema = DefaultSchema>\n implements ClientTransaction<TSchema>\n{\n readonly location = 'client';\n readonly mutate: TransactionMutate<TSchema>;\n /**\n * @deprecated Use {@linkcode createBuilder} with `tx.run(zql.table.where(...))` instead.\n */\n readonly query: SchemaQuery<TSchema>;\n\n readonly #repTx: WriteTransaction;\n readonly #zeroContext: ZeroContext;\n\n constructor(lc: LogContext, repTx: WriteTransaction, schema: TSchema) {\n must(repTx.reason === 'initial' || repTx.reason === 'rebase');\n const txData = getZeroTxData(repTx);\n const ivmBranch = txData.ivmSources as IVMSourceBranch;\n\n this.#repTx = repTx;\n\n const executor = makeCRUDExecutor(repTx, schema, ivmBranch);\n this.mutate = makeTransactionMutate(schema, executor);\n\n const zeroContext = newZeroContext(\n lc,\n txData.ivmSources as IVMSourceBranch,\n );\n\n this.query = createRunnableBuilder(zeroContext, schema);\n\n this.#zeroContext = zeroContext;\n }\n\n get clientID(): ClientID {\n return this.#repTx.clientID;\n }\n\n get mutationID(): number {\n return this.#repTx.mutationID;\n }\n\n get reason(): 'optimistic' | 'rebase' {\n return this.#repTx.reason === 'initial' ? 'optimistic' : 'rebase';\n }\n\n get token(): string | undefined {\n return (this.#repTx as WriteTransactionImpl)[zeroData]?.token;\n }\n\n run<TTable extends keyof TSchema['tables'] & string, TReturn>(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return this.#zeroContext.run(query, options);\n }\n}\n\nexport function getZeroTxData(repTx: WriteTransaction): ZeroTxData {\n const txData = must(\n (repTx as WriteTransactionImpl)[zeroData],\n 'zero was not set on replicache internal options!',\n );\n return txData as ZeroTxData;\n}\n\nexport function makeReplicacheMutator<\n S extends Schema,\n TWrappedTransaction,\n Context,\n>(\n lc: LogContext,\n mutator: CustomMutatorImpl<S, TWrappedTransaction>,\n schema: S,\n context: Context,\n): (repTx: WriteTransaction, args: ReadonlyJSONValue) => Promise<void> {\n return async (\n repTx: WriteTransaction,\n args: ReadonlyJSONValue,\n ): Promise<void> => {\n const tx = new TransactionImpl(lc, repTx, schema);\n await mutator(tx, args, context);\n };\n}\n\nfunction assertValidRunOptions(options: RunOptions | undefined): void {\n // TODO(arv): We should enforce this with the type system too.\n assert(\n options?.type !== 'complete',\n 'Cannot wait for complete results in custom mutations',\n );\n}\n\nfunction newZeroContext(lc: LogContext, ivmBranch: IVMSourceBranch) {\n return new ZeroContext(\n lc,\n ivmBranch,\n () => emptyFunction,\n () => emptyFunction,\n emptyFunction,\n emptyFunction,\n emptyFunction,\n applyViewUpdates => applyViewUpdates(),\n emptyFunction,\n assertValidRunOptions,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAoHO,MAAM,gBAEb;AAAA,EACW,WAAW;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EAEA;AAAA,EACA;AAAA,EAET,YAAY,IAAgB,OAAyB,QAAiB;AACpE,SAAK,MAAM,WAAW,aAAa,MAAM,WAAW,QAAQ;AAC5D,UAAM,SAAS,cAAc,KAAK;AAClC,UAAM,YAAY,OAAO;AAEzB,SAAK,SAAS;AAEd,UAAM,WAAW,iBAAiB,OAAO,QAAQ,SAAS;AAC1D,SAAK,SAAS,sBAAsB,QAAQ,QAAQ;AAEpD,UAAM,cAAc;AAAA,MAClB;AAAA,MACA,OAAO;AAAA,IAAA;AAGT,SAAK,QAAQ,sBAAsB,aAAa,MAAM;AAEtD,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,IAAI,WAAqB;AACvB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,aAAqB;AACvB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,SAAkC;AACpC,WAAO,KAAK,OAAO,WAAW,YAAY,eAAe;AAAA,EAC3D;AAAA,EAEA,IAAI,QAA4B;AAC9B,WAAQ,KAAK,OAAgC,QAAQ,GAAG;AAAA,EAC1D;AAAA,EAEA,IACE,OACA,SACiC;AACjC,WAAO,KAAK,aAAa,IAAI,OAAO,OAAO;AAAA,EAC7C;AACF;AAEO,SAAS,cAAc,OAAqC;AACjE,QAAM,SAAS;AAAA,IACZ,MAA+B,QAAQ;AAAA,IACxC;AAAA,EAAA;AAEF,SAAO;AACT;AAEO,SAAS,sBAKd,IACA,SACA,QACA,SACqE;AACrE,SAAO,OACL,OACA,SACkB;AAClB,UAAM,KAAK,IAAI,gBAAgB,IAAI,OAAO,MAAM;AAChD,UAAM,QAAQ,IAAI,MAAM,OAAO;AAAA,EACjC;AACF;AAEA,SAAS,sBAAsB,SAAuC;AAEpE;AAAA,IACE,SAAS,SAAS;AAAA,IAClB;AAAA,EAAA;AAEJ;AAEA,SAAS,eAAe,IAAgB,WAA4B;AAClE,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,sBAAoB,iBAAA;AAAA,IACpB;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -27,7 +27,7 @@ import type { MutatorProxy } from './mutator-proxy.ts';
|
|
|
27
27
|
* using different separators ('.' for mutator definitions, '|' for custom functions) and wraps them
|
|
28
28
|
* using the mutator proxy.
|
|
29
29
|
*/
|
|
30
|
-
export declare function
|
|
30
|
+
export declare function addCustomMutatorsProperties(mutators: CustomMutatorDefs, mutatorProxy: MutatorProxy, mutateObject: Record<string, unknown>, replicacheMutate: Record<string, unknown>): void;
|
|
31
31
|
/**
|
|
32
32
|
* Builds the mutate type from legacy CustomMutatorDefs, handling arbitrary nesting.
|
|
33
33
|
* Each node can be either a CustomMutatorImpl function or a namespace containing more mutators.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-mutate-property.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/make-mutate-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"make-mutate-property.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/make-mutate-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAEjE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,iBAAiB,EAC3B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,IAAI,CAkCN;AAED;;;GAGG;AACH,KAAK,0BAA0B,CAC7B,CAAC,SAAS,MAAM,EAChB,EAAE,SAAS,iBAAiB,EAC5B,CAAC,IACC;IACF,QAAQ,EAAE,CAAC,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CACtC,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,EAClB,GAAG,IAAI,EAAE,MAAM,IAAI,KAChB,OAAO,CAAC,IAAI,CAAC,GACd,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,aAAa,GAChC,EAAE,CAAC,CAAC,CAAC,SAAS,iBAAiB,GAC7B,0BAA0B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACvC,KAAK;CACZ,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAChC,CAAC,SAAS,MAAM,EAChB,EAAE,SAAS,iBAAiB,GAAG,SAAS,EACxC,CAAC,IACC,EAAE,SAAS,iBAAiB,GAC5B,CAAC,CAAC,sBAAsB,CAAC,SAAS,IAAI,GACpC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,GAC7D,0BAA0B,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GACtC,SAAS,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { must } from "../../../shared/src/must.js";
|
|
2
2
|
import { customMutatorKey } from "../../../zql/src/mutate/custom.js";
|
|
3
|
-
function
|
|
3
|
+
function addCustomMutatorsProperties(mutators, mutatorProxy, mutateObject, replicacheMutate) {
|
|
4
4
|
const processMutators = (mutators2, path, mutateObject2) => {
|
|
5
5
|
for (const [key, mutator] of Object.entries(mutators2)) {
|
|
6
6
|
path.push(key);
|
|
@@ -28,6 +28,6 @@ function makeMutateProperty(mutators, mutatorProxy, mutateObject, replicacheMuta
|
|
|
28
28
|
processMutators(mutators, [], mutateObject);
|
|
29
29
|
}
|
|
30
30
|
export {
|
|
31
|
-
|
|
31
|
+
addCustomMutatorsProperties
|
|
32
32
|
};
|
|
33
33
|
//# sourceMappingURL=make-mutate-property.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-mutate-property.js","sources":["../../../../../zero-client/src/client/make-mutate-property.ts"],"sourcesContent":["import type {DeepMerge} from '../../../shared/src/deep-merge.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n customMutatorKey,\n type Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport type {DBMutator} from './crud.ts';\nimport type {CustomMutatorDefs, MutatorResult} from './custom.ts';\nimport type {MutatorProxy} from './mutator-proxy.ts';\n\n/**\n * Creates and populates a mutate property object by processing mutator definitions recursively.\n *\n * This function traverses through mutator definitions (either schema-based or custom) and builds\n * a corresponding object structure where each mutator is wrapped by the mutator proxy. It handles\n * both flat mutator functions and nested mutator definition objects.\n *\n * @template S - The schema type that defines the structure of the data\n * @template C - The context type used by mutators, defaults to unknown\n *\n * @param mutators - The mutator definitions to process, can be schema-based or custom mutator definitions\n * @param mutatorProxy - The proxy object responsible for wrapping mutators with additional functionality\n * @param mutateObject - The target object to populate with wrapped mutators\n * @param replicacheMutate - The source object containing the actual mutator implementations to wrap\n *\n * @returns void - This function mutates the mutateObject parameter directly\n *\n * @remarks\n * The function recursively processes nested mutator structures, creating corresponding nested objects\n * in the mutateObject. For leaf mutators (functions or mutator definitions), it generates a full key\n * using different separators ('.' for mutator definitions, '|' for custom functions) and wraps them\n * using the mutator proxy.\n */\nexport function
|
|
1
|
+
{"version":3,"file":"make-mutate-property.js","sources":["../../../../../zero-client/src/client/make-mutate-property.ts"],"sourcesContent":["import type {DeepMerge} from '../../../shared/src/deep-merge.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n customMutatorKey,\n type Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport type {DBMutator} from './crud.ts';\nimport type {CustomMutatorDefs, MutatorResult} from './custom.ts';\nimport type {MutatorProxy} from './mutator-proxy.ts';\n\n/**\n * Creates and populates a mutate property object by processing mutator definitions recursively.\n *\n * This function traverses through mutator definitions (either schema-based or custom) and builds\n * a corresponding object structure where each mutator is wrapped by the mutator proxy. It handles\n * both flat mutator functions and nested mutator definition objects.\n *\n * @template S - The schema type that defines the structure of the data\n * @template C - The context type used by mutators, defaults to unknown\n *\n * @param mutators - The mutator definitions to process, can be schema-based or custom mutator definitions\n * @param mutatorProxy - The proxy object responsible for wrapping mutators with additional functionality\n * @param mutateObject - The target object to populate with wrapped mutators\n * @param replicacheMutate - The source object containing the actual mutator implementations to wrap\n *\n * @returns void - This function mutates the mutateObject parameter directly\n *\n * @remarks\n * The function recursively processes nested mutator structures, creating corresponding nested objects\n * in the mutateObject. For leaf mutators (functions or mutator definitions), it generates a full key\n * using different separators ('.' for mutator definitions, '|' for custom functions) and wraps them\n * using the mutator proxy.\n */\nexport function addCustomMutatorsProperties(\n mutators: CustomMutatorDefs,\n mutatorProxy: MutatorProxy,\n mutateObject: Record<string, unknown>,\n replicacheMutate: Record<string, unknown>,\n): void {\n const processMutators = (\n mutators: CustomMutatorDefs,\n path: string[],\n mutateObject: Record<string, unknown>,\n ) => {\n for (const [key, mutator] of Object.entries(mutators)) {\n path.push(key);\n if (typeof mutator === 'function') {\n const fullKey = customMutatorKey('|', path);\n mutateObject[key] = mutatorProxy.wrapCustomMutator(\n fullKey,\n must(replicacheMutate[fullKey]) as unknown as (\n ...args: unknown[]\n ) => MutatorResult,\n );\n } else {\n // Nested namespace - recursive build and process.\n let existing = mutateObject[key];\n if (existing === undefined) {\n existing = {};\n mutateObject[key] = existing;\n }\n processMutators(\n mutator as CustomMutatorDefs,\n path,\n existing as Record<string, unknown>,\n );\n }\n path.pop();\n }\n };\n\n processMutators(mutators, [], mutateObject);\n}\n\n/**\n * Builds the mutate type from legacy CustomMutatorDefs, handling arbitrary nesting.\n * Each node can be either a CustomMutatorImpl function or a namespace containing more mutators.\n */\ntype MakeFromMutatorDefinitions<\n S extends Schema,\n MD extends CustomMutatorDefs,\n C,\n> = {\n readonly [K in keyof MD]: MD[K] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<void>\n ? (...args: Args) => MutatorResult\n : MD[K] extends CustomMutatorDefs\n ? MakeFromMutatorDefinitions<S, MD[K], C>\n : never;\n};\n\nexport type MakeMutatePropertyType<\n S extends Schema,\n MD extends CustomMutatorDefs | undefined,\n C,\n> = MD extends CustomMutatorDefs\n ? S['enableLegacyMutators'] extends true\n ? DeepMerge<DBMutator<S>, MakeFromMutatorDefinitions<S, MD, C>>\n : MakeFromMutatorDefinitions<S, MD, C>\n : DBMutator<S>;\n"],"names":["mutators","mutateObject"],"mappings":";;AAkCO,SAAS,4BACd,UACA,cACA,cACA,kBACM;AACN,QAAM,kBAAkB,CACtBA,WACA,MACAC,kBACG;AACH,eAAW,CAAC,KAAK,OAAO,KAAK,OAAO,QAAQD,SAAQ,GAAG;AACrD,WAAK,KAAK,GAAG;AACb,UAAI,OAAO,YAAY,YAAY;AACjC,cAAM,UAAU,iBAAiB,KAAK,IAAI;AAC1CC,sBAAa,GAAG,IAAI,aAAa;AAAA,UAC/B;AAAA,UACA,KAAK,iBAAiB,OAAO,CAAC;AAAA,QAAA;AAAA,MAIlC,OAAO;AAEL,YAAI,WAAWA,cAAa,GAAG;AAC/B,YAAI,aAAa,QAAW;AAC1B,qBAAW,CAAA;AACXA,wBAAa,GAAG,IAAI;AAAA,QACtB;AACA;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,MAEJ;AACA,WAAK,IAAA;AAAA,IACP;AAAA,EACF;AAEA,kBAAgB,UAAU,CAAA,GAAI,YAAY;AAC5C;"}
|
|
@@ -72,19 +72,18 @@ class MutatorProxy {
|
|
|
72
72
|
if (cachedPromise) {
|
|
73
73
|
return cachedPromise;
|
|
74
74
|
}
|
|
75
|
-
this.#lc.error?.(
|
|
76
|
-
`Mutator "${name}" error on ${origin}`,
|
|
77
|
-
args[0],
|
|
78
|
-
error
|
|
79
|
-
);
|
|
80
75
|
if (isZeroError(error)) {
|
|
76
|
+
this.#lc.error?.(`Mutator "${name}" error on ${origin}`, error);
|
|
81
77
|
const zeroErrorPromise = this.#makeZeroErrorResultDetails(error);
|
|
82
78
|
cachedMutationPromises[origin] = zeroErrorPromise;
|
|
83
79
|
return zeroErrorPromise;
|
|
84
80
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
81
|
+
const applicationError = wrapWithApplicationError(error);
|
|
82
|
+
this.#lc.error?.(
|
|
83
|
+
`Mutator "${name}" app error on ${origin}`,
|
|
84
|
+
applicationError
|
|
87
85
|
);
|
|
86
|
+
const applicationErrorPromise = this.#makeApplicationErrorResultDetails(applicationError);
|
|
88
87
|
cachedMutationPromises[origin] = applicationErrorPromise;
|
|
89
88
|
return applicationErrorPromise;
|
|
90
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutator-proxy.js","sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {ApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {wrapWithApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport type {\n ConnectionManager,\n ConnectionManagerState,\n} from './connection-manager.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport type {\n MutatorResult,\n MutatorResultErrorDetails,\n MutatorResultSuccessDetails,\n} from './custom.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\nconst successResultDetails = {\n type: 'success',\n} as const satisfies MutatorResultSuccessDetails;\nconst successResult = () => successResultDetails;\n\ntype CachedMutationRejection = {\n readonly error: ZeroError;\n readonly promise: Promise<MutatorResultErrorDetails>;\n};\n\nexport class MutatorProxy {\n readonly #lc: LogContext;\n readonly #connectionManager: ConnectionManager;\n readonly #mutationTracker: MutationTracker;\n #mutationRejection: CachedMutationRejection | undefined;\n\n constructor(\n lc: LogContext,\n connectionManager: ConnectionManager,\n mutationTracker: MutationTracker,\n ) {\n this.#lc = lc;\n this.#connectionManager = connectionManager;\n this.#mutationTracker = mutationTracker;\n\n this.#connectionManager.subscribe(state =>\n this.#onConnectionStateChange(state),\n );\n this.#onConnectionStateChange(connectionManager.state);\n }\n\n get mutationRejectionError(): ZeroError | undefined {\n return this.#mutationRejection?.error;\n }\n\n /**\n * Called when the connection state changes.\n *\n * If the connection state is disconnected, error, or closed, the\n * mutation rejection error is set and all outstanding `.server` promises in\n * the mutation tracker are rejected with the error.\n */\n #onConnectionStateChange(state: ConnectionManagerState) {\n // we short circuit the rejection if the error is due to a missing cacheURL\n // this allows local writes to continue\n if (\n state.name === ConnectionStatus.Disconnected &&\n state.reason.kind === ClientErrorKind.NoSocketOrigin\n ) {\n this.#mutationRejection = undefined;\n return;\n }\n\n switch (state.name) {\n case ConnectionStatus.Disconnected:\n case ConnectionStatus.Error:\n case ConnectionStatus.Closed:\n this.#mutationRejection = {\n error: state.reason,\n promise: Promise.resolve(\n this.#makeZeroErrorResultDetails(state.reason),\n ),\n };\n this.#mutationTracker.rejectAllOutstandingMutations(state.reason);\n break;\n case ConnectionStatus.Connected:\n case ConnectionStatus.Connecting:\n case ConnectionStatus.NeedsAuth:\n this.#mutationRejection = undefined;\n return;\n default:\n unreachable(state);\n }\n }\n\n wrapCustomMutator<\n F extends (...args: [] | [ReadonlyJSONValue]) => {\n client: Promise<unknown>;\n server: Promise<unknown>;\n },\n >(name: string, f: F): (...args: Parameters<F>) => MutatorResult {\n return (...args) => {\n if (this.#mutationRejection) {\n return {\n client: this.#mutationRejection.promise,\n server: this.#mutationRejection.promise,\n } as const satisfies MutatorResult;\n }\n\n let result: {\n client: Promise<unknown>;\n server: Promise<unknown>;\n };\n\n const cachedMutationPromises: Partial<\n Record<'client' | 'server', Promise<MutatorResultErrorDetails>>\n > = {};\n\n const wrapErrorFor =\n (origin: 'client' | 'server') =>\n (error: unknown): Promise<MutatorResultErrorDetails> => {\n const cachedPromise = cachedMutationPromises[origin];\n if (cachedPromise) {\n return cachedPromise;\n }\n\n this.#lc.error?.(
|
|
1
|
+
{"version":3,"file":"mutator-proxy.js","sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {ApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {wrapWithApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport type {\n ConnectionManager,\n ConnectionManagerState,\n} from './connection-manager.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport type {\n MutatorResult,\n MutatorResultErrorDetails,\n MutatorResultSuccessDetails,\n} from './custom.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\nconst successResultDetails = {\n type: 'success',\n} as const satisfies MutatorResultSuccessDetails;\nconst successResult = () => successResultDetails;\n\ntype CachedMutationRejection = {\n readonly error: ZeroError;\n readonly promise: Promise<MutatorResultErrorDetails>;\n};\n\nexport class MutatorProxy {\n readonly #lc: LogContext;\n readonly #connectionManager: ConnectionManager;\n readonly #mutationTracker: MutationTracker;\n #mutationRejection: CachedMutationRejection | undefined;\n\n constructor(\n lc: LogContext,\n connectionManager: ConnectionManager,\n mutationTracker: MutationTracker,\n ) {\n this.#lc = lc;\n this.#connectionManager = connectionManager;\n this.#mutationTracker = mutationTracker;\n\n this.#connectionManager.subscribe(state =>\n this.#onConnectionStateChange(state),\n );\n this.#onConnectionStateChange(connectionManager.state);\n }\n\n get mutationRejectionError(): ZeroError | undefined {\n return this.#mutationRejection?.error;\n }\n\n /**\n * Called when the connection state changes.\n *\n * If the connection state is disconnected, error, or closed, the\n * mutation rejection error is set and all outstanding `.server` promises in\n * the mutation tracker are rejected with the error.\n */\n #onConnectionStateChange(state: ConnectionManagerState) {\n // we short circuit the rejection if the error is due to a missing cacheURL\n // this allows local writes to continue\n if (\n state.name === ConnectionStatus.Disconnected &&\n state.reason.kind === ClientErrorKind.NoSocketOrigin\n ) {\n this.#mutationRejection = undefined;\n return;\n }\n\n switch (state.name) {\n case ConnectionStatus.Disconnected:\n case ConnectionStatus.Error:\n case ConnectionStatus.Closed:\n this.#mutationRejection = {\n error: state.reason,\n promise: Promise.resolve(\n this.#makeZeroErrorResultDetails(state.reason),\n ),\n };\n this.#mutationTracker.rejectAllOutstandingMutations(state.reason);\n break;\n case ConnectionStatus.Connected:\n case ConnectionStatus.Connecting:\n case ConnectionStatus.NeedsAuth:\n this.#mutationRejection = undefined;\n return;\n default:\n unreachable(state);\n }\n }\n\n wrapCustomMutator<\n F extends (...args: [] | [ReadonlyJSONValue]) => {\n client: Promise<unknown>;\n server: Promise<unknown>;\n },\n >(name: string, f: F): (...args: Parameters<F>) => MutatorResult {\n return (...args) => {\n if (this.#mutationRejection) {\n return {\n client: this.#mutationRejection.promise,\n server: this.#mutationRejection.promise,\n } as const satisfies MutatorResult;\n }\n\n let result: {\n client: Promise<unknown>;\n server: Promise<unknown>;\n };\n\n const cachedMutationPromises: Partial<\n Record<'client' | 'server', Promise<MutatorResultErrorDetails>>\n > = {};\n\n const wrapErrorFor =\n (origin: 'client' | 'server') =>\n (error: unknown): Promise<MutatorResultErrorDetails> => {\n const cachedPromise = cachedMutationPromises[origin];\n if (cachedPromise) {\n return cachedPromise;\n }\n\n if (isZeroError(error)) {\n this.#lc.error?.(`Mutator \"${name}\" error on ${origin}`, error);\n\n const zeroErrorPromise = this.#makeZeroErrorResultDetails(error);\n cachedMutationPromises[origin] = zeroErrorPromise;\n return zeroErrorPromise;\n }\n\n const applicationError = wrapWithApplicationError(error);\n this.#lc.error?.(\n `Mutator \"${name}\" app error on ${origin}`,\n applicationError,\n );\n\n const applicationErrorPromise =\n this.#makeApplicationErrorResultDetails(applicationError);\n cachedMutationPromises[origin] = applicationErrorPromise;\n return applicationErrorPromise;\n };\n\n try {\n result = f(...args);\n } catch (error) {\n const clientPromise = wrapErrorFor('client')(error);\n const serverPromise = wrapErrorFor('server')(error);\n\n return {\n client: clientPromise,\n server: serverPromise,\n } as const satisfies MutatorResult;\n }\n\n const client = this.#normalizeResultPromise(\n result.client,\n wrapErrorFor('client'),\n );\n const server = this.#normalizeResultPromise(\n result.server,\n wrapErrorFor('server'),\n );\n\n return {\n client,\n server,\n };\n };\n }\n\n #normalizeResultPromise(\n promise: Promise<unknown>,\n wrapError: (error: unknown) => Promise<MutatorResultErrorDetails>,\n ) {\n return promise.then<MutatorResultSuccessDetails, MutatorResultErrorDetails>(\n successResult,\n wrapError,\n );\n }\n\n #makeZeroErrorResultDetails(zeroError: ZeroError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'zero',\n message: zeroError.message,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n\n #makeApplicationErrorResultDetails(applicationError: ApplicationError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'app',\n message: applicationError.message,\n details: applicationError.details,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n}\n"],"names":["ConnectionStatus.Disconnected","ClientErrorKind.NoSocketOrigin","ConnectionStatus.Error","ConnectionStatus.Closed","ConnectionStatus.Connected","ConnectionStatus.Connecting","ConnectionStatus.NeedsAuth"],"mappings":";;;;;AAmBA,MAAM,uBAAuB;AAAA,EAC3B,MAAM;AACR;AACA,MAAM,gBAAgB,MAAM;AAOrB,MAAM,aAAa;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACT;AAAA,EAEA,YACE,IACA,mBACA,iBACA;AACA,SAAK,MAAM;AACX,SAAK,qBAAqB;AAC1B,SAAK,mBAAmB;AAExB,SAAK,mBAAmB;AAAA,MAAU,CAAA,UAChC,KAAK,yBAAyB,KAAK;AAAA,IAAA;AAErC,SAAK,yBAAyB,kBAAkB,KAAK;AAAA,EACvD;AAAA,EAEA,IAAI,yBAAgD;AAClD,WAAO,KAAK,oBAAoB;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,yBAAyB,OAA+B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,UAAI;AACF,iBAAS,EAAE,GAAG,IAAI;AAAA,MACpB,SAAS,OAAO;AACd,cAAM,gBAAgB,aAAa,QAAQ,EAAE,KAAK;AAClD,cAAM,gBAAgB,aAAa,QAAQ,EAAE,KAAK;AAElD,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,QAAQ;AAAA,QAAA;AAAA,MAEZ;AAEA,YAAM,SAAS,KAAK;AAAA,QAClB,OAAO;AAAA,QACP,aAAa,QAAQ;AAAA,MAAA;AAEvB,YAAM,SAAS,KAAK;AAAA,QAClB,OAAO;AAAA,QACP,aAAa,QAAQ;AAAA,MAAA;AAGvB,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AAAA,EAEA,wBACE,SACA,WACA;AACA,WAAO,QAAQ;AAAA,MACb;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,4BAA4B,WAAsB;AAChD,WAAO,QAAQ,QAAQ;AAAA,MACrB,MAAM;AAAA,MACN,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,UAAU;AAAA,MAAA;AAAA,IACrB,CAC4C;AAAA,EAChD;AAAA,EAEA,mCAAmC,kBAAoC;AACrE,WAAO,QAAQ,QAAQ;AAAA,MACrB,MAAM;AAAA,MACN,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,iBAAiB;AAAA,QAC1B,SAAS,iBAAiB;AAAA,MAAA;AAAA,IAC5B,CAC4C;AAAA,EAChD;AACF;"}
|
|
@@ -74,6 +74,7 @@ export interface ReplicacheInternalAPI {
|
|
|
74
74
|
lastMutationID(): number;
|
|
75
75
|
}
|
|
76
76
|
export declare function getInternalReplicacheImplForTesting(z: object): ReplicacheImpl<MutatorDefs>;
|
|
77
|
+
export type ZeroMutate<S extends Schema, MD extends CustomMutatorDefs | undefined, C> = MakeMutatePropertyType<S, MD, C> & ((mr: MutateRequest<any, S, C, any>) => MutatorResult);
|
|
77
78
|
export declare class Zero<const S extends Schema = DefaultSchema, MD extends CustomMutatorDefs | undefined = undefined, C = DefaultContext> {
|
|
78
79
|
#private;
|
|
79
80
|
readonly version: string;
|
|
@@ -208,13 +209,23 @@ export declare class Zero<const S extends Schema = DefaultSchema, MD extends Cus
|
|
|
208
209
|
get clientID(): ClientID;
|
|
209
210
|
get clientGroupID(): Promise<ClientGroupID>;
|
|
210
211
|
/**
|
|
211
|
-
*
|
|
212
|
+
* Use to execute mutations. The primary flow is to call
|
|
213
|
+
* `zero.mutate(mutationRequest)` with your registered custom mutators:
|
|
212
214
|
*
|
|
213
|
-
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* await zero.mutate(
|
|
217
|
+
* mutators.myMutator({id: '1', title: 'First issue'}),
|
|
218
|
+
* );
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* When `schema.enableLegacyMutators` is true, legacy conveniences are added:
|
|
222
|
+
* - Table-scoped CRUD helpers, e.g. `zero.mutate.issue.create` / `set` / `update` / `delete`
|
|
223
|
+
* - Your custom mutators exposed directly on `zero.mutate`
|
|
214
224
|
*
|
|
215
225
|
* ```ts
|
|
216
226
|
* await zero.mutate.issue.create({id: '1', title: 'First issue', priority: 'high'});
|
|
217
227
|
* await zero.mutate.comment.create({id: '1', text: 'First comment', issueID: '1'});
|
|
228
|
+
* await zero.mutate.myMutator({id: '1', title: 'First issue'});
|
|
218
229
|
* ```
|
|
219
230
|
*
|
|
220
231
|
* The `update` methods support partials. Unspecified or `undefined` fields
|
|
@@ -225,7 +236,7 @@ export declare class Zero<const S extends Schema = DefaultSchema, MD extends Cus
|
|
|
225
236
|
* await zero.mutate.issue.update({id: '1', title: 'Updated title'});
|
|
226
237
|
* ```
|
|
227
238
|
*/
|
|
228
|
-
readonly mutate:
|
|
239
|
+
readonly mutate: ZeroMutate<S, MD, C>;
|
|
229
240
|
/**
|
|
230
241
|
* Provides a way to batch multiple CRUD mutations together:
|
|
231
242
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3D,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAAE,eAAe,CAAC,EACjE,eAAe,SAAW,GACzB,OAAO,CACR;IACE,SAAS;IACT,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,SAAS;IACzC,iBAAiB,GAAG,SAAS;CAC9B,CACF,CAmEA;AAED,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,UAAU,GAAG,QAAQ,EACnC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,EAC1C,SAAS,EAAE,OAAO,EAClB,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3D,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,gBA6B3D"}
|
|
@@ -39,7 +39,7 @@ import { ConnectionManager, throwIfConnectionError } from "./connection-manager.
|
|
|
39
39
|
import { Connected, Closed, Disconnected, Connecting, Error as Error$1, NeedsAuth } from "./connection-status-enum.js";
|
|
40
40
|
import { ConnectionImpl } from "./connection.js";
|
|
41
41
|
import { ZeroContext } from "./context.js";
|
|
42
|
-
import {
|
|
42
|
+
import { makeCRUDMutateBatch, addTableCRUDProperties } from "./crud.js";
|
|
43
43
|
import { DeleteClientsManager } from "./delete-clients-manager.js";
|
|
44
44
|
import { shouldEnableAnalytics } from "./enable-analytics.js";
|
|
45
45
|
import { ClientError, getErrorConnectionTransition, NO_STATUS_TRANSITION, isClientError, isAuthError, isServerError, getBackoffParams } from "./error.js";
|
|
@@ -47,7 +47,7 @@ import { toWSString, appendPath } from "./http-string.js";
|
|
|
47
47
|
import { Inspector } from "./inspector/inspector.js";
|
|
48
48
|
import { IVMSourceBranch } from "./ivm-branch.js";
|
|
49
49
|
import { createLogOptions } from "./log-options.js";
|
|
50
|
-
import {
|
|
50
|
+
import { addCustomMutatorsProperties } from "./make-mutate-property.js";
|
|
51
51
|
import { makeReplicacheMutators } from "./make-replicache-mutators.js";
|
|
52
52
|
import { MetricManager, REPORT_INTERVAL_MS, shouldReportConnectError, getLastConnectErrorValue, DID_NOT_CONNECT_VALUE } from "./metrics.js";
|
|
53
53
|
import { MutationTracker } from "./mutation-tracker.js";
|
|
@@ -411,9 +411,12 @@ class Zero {
|
|
|
411
411
|
repMutator
|
|
412
412
|
)(mr.args);
|
|
413
413
|
};
|
|
414
|
-
const mutateBatch =
|
|
414
|
+
const mutateBatch = makeCRUDMutateBatch(schema, rep.mutate);
|
|
415
|
+
if (schema.enableLegacyMutators) {
|
|
416
|
+
addTableCRUDProperties(schema, callableMutate, rep.mutate);
|
|
417
|
+
}
|
|
415
418
|
if (mutators && !isMutatorRegistry(mutators)) {
|
|
416
|
-
|
|
419
|
+
addCustomMutatorsProperties(
|
|
417
420
|
mutators,
|
|
418
421
|
mutatorProxy,
|
|
419
422
|
callableMutate,
|
|
@@ -623,13 +626,23 @@ class Zero {
|
|
|
623
626
|
return this.#rep.clientGroupID;
|
|
624
627
|
}
|
|
625
628
|
/**
|
|
626
|
-
*
|
|
629
|
+
* Use to execute mutations. The primary flow is to call
|
|
630
|
+
* `zero.mutate(mutationRequest)` with your registered custom mutators:
|
|
631
|
+
*
|
|
632
|
+
* ```ts
|
|
633
|
+
* await zero.mutate(
|
|
634
|
+
* mutators.myMutator({id: '1', title: 'First issue'}),
|
|
635
|
+
* );
|
|
636
|
+
* ```
|
|
627
637
|
*
|
|
628
|
-
*
|
|
638
|
+
* When `schema.enableLegacyMutators` is true, legacy conveniences are added:
|
|
639
|
+
* - Table-scoped CRUD helpers, e.g. `zero.mutate.issue.create` / `set` / `update` / `delete`
|
|
640
|
+
* - Your custom mutators exposed directly on `zero.mutate`
|
|
629
641
|
*
|
|
630
642
|
* ```ts
|
|
631
643
|
* await zero.mutate.issue.create({id: '1', title: 'First issue', priority: 'high'});
|
|
632
644
|
* await zero.mutate.comment.create({id: '1', text: 'First comment', issueID: '1'});
|
|
645
|
+
* await zero.mutate.myMutator({id: '1', title: 'First issue'});
|
|
633
646
|
* ```
|
|
634
647
|
*
|
|
635
648
|
* The `update` methods support partials. Unspecified or `undefined` fields
|