@prisma/orm-family-sql 8.0.0-rc.24-dev.6 → 8.0.0-rc.24-dev.8
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/dist/orm-client.d.mts +39 -29
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +80 -24
- package/dist/orm-client.mjs.map +1 -1
- package/package.json +18 -18
package/dist/orm-client.mjs
CHANGED
|
@@ -5344,7 +5344,7 @@ function createFilteredRelationMutator(related) {
|
|
|
5344
5344
|
};
|
|
5345
5345
|
}
|
|
5346
5346
|
function createRelationMutator(related) {
|
|
5347
|
-
|
|
5347
|
+
const mutator = {
|
|
5348
5348
|
...createFilteredRelationMutator(related),
|
|
5349
5349
|
create(data) {
|
|
5350
5350
|
return {
|
|
@@ -5352,6 +5352,13 @@ function createRelationMutator(related) {
|
|
|
5352
5352
|
data: Array.isArray(data) ? [...data] : [data]
|
|
5353
5353
|
};
|
|
5354
5354
|
},
|
|
5355
|
+
variant(value) {
|
|
5356
|
+
const { variantValue } = related.variant(value).state;
|
|
5357
|
+
return { create: (data) => ({
|
|
5358
|
+
...mutator.create(data),
|
|
5359
|
+
...ifDefined("variant", variantValue)
|
|
5360
|
+
}) };
|
|
5361
|
+
},
|
|
5355
5362
|
connect(criteria) {
|
|
5356
5363
|
return {
|
|
5357
5364
|
kind: "connect",
|
|
@@ -5366,6 +5373,7 @@ function createRelationMutator(related) {
|
|
|
5366
5373
|
};
|
|
5367
5374
|
}
|
|
5368
5375
|
};
|
|
5376
|
+
return mutator;
|
|
5369
5377
|
}
|
|
5370
5378
|
function isRelationMutationDescriptor(value) {
|
|
5371
5379
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -5624,13 +5632,33 @@ function addCreateWithRelations(t, model, parsed, { keysFromParent, returns, sha
|
|
|
5624
5632
|
afterWrite: (inserted) => addAfterWrite(t, model, inserted, parsed.relationMutations)
|
|
5625
5633
|
});
|
|
5626
5634
|
}
|
|
5627
|
-
function nestedCreate(t, model, parsed, keysFromParent, returns) {
|
|
5635
|
+
function nestedCreate(t, model, parsed, keysFromParent, returns, variantValue) {
|
|
5628
5636
|
return addCreateWithRelations(t, model, parsed, {
|
|
5629
5637
|
keysFromParent,
|
|
5630
5638
|
returns,
|
|
5631
5639
|
shape: allColumns,
|
|
5632
|
-
variantValue
|
|
5640
|
+
variantValue
|
|
5641
|
+
});
|
|
5642
|
+
}
|
|
5643
|
+
function addVariantInOwnTable(t, { relation, relatedCollection }, { data, variant }, keys, added) {
|
|
5644
|
+
if (variant === void 0) return false;
|
|
5645
|
+
const collection = {
|
|
5646
|
+
context: t.context,
|
|
5647
|
+
state: relatedCollection(relation).variant(variant).state,
|
|
5648
|
+
modelName: relation.to,
|
|
5649
|
+
namespaceId: relation.toNamespace
|
|
5650
|
+
};
|
|
5651
|
+
const mti = mtiCreateContextOf(collection);
|
|
5652
|
+
if (mti === void 0) return false;
|
|
5653
|
+
for (const row of data) parseCreateInput(t, modelOf(collection), row, relatedCollection);
|
|
5654
|
+
assertReturningCapability(t.context.contract, "create()");
|
|
5655
|
+
createAllVariantGraph(collection, requireVariantTable(collection.state.tables, mti.variant.value), mti, data, {
|
|
5656
|
+
graph: t.graph,
|
|
5657
|
+
keys,
|
|
5658
|
+
requires: keys.length === 0 ? parentRowRequired(t) : [],
|
|
5659
|
+
added
|
|
5633
5660
|
});
|
|
5661
|
+
return true;
|
|
5634
5662
|
}
|
|
5635
5663
|
function addBeforeWrite(t, model, relationMutations) {
|
|
5636
5664
|
const { parentOwned, junctionOwned } = partitionByOwnership(relationMutations);
|
|
@@ -5644,7 +5672,7 @@ function addBeforeWrite(t, model, relationMutations) {
|
|
|
5644
5672
|
for (const relationMutation of parentOwned) for (const mutation of relationMutation.mutations) {
|
|
5645
5673
|
if (isFilteredWrite(mutation)) continue;
|
|
5646
5674
|
if (mutation.kind === "disconnect") for (const column of localColumnsOf(t.context.contract, model, relationMutation.relation)) nullColumns[column] = null;
|
|
5647
|
-
else keys.push(addParentOwned(t, model, relationMutation, mutation));
|
|
5675
|
+
else keys.push(...addParentOwned(t, model, relationMutation, mutation));
|
|
5648
5676
|
}
|
|
5649
5677
|
return {
|
|
5650
5678
|
keys,
|
|
@@ -5684,10 +5712,22 @@ function addParentOwned(t, model, { name, relation, relatedCollection }, mutatio
|
|
|
5684
5712
|
relation: name,
|
|
5685
5713
|
problem: "missing-data"
|
|
5686
5714
|
} });
|
|
5687
|
-
|
|
5688
|
-
|
|
5715
|
+
const keys = [];
|
|
5716
|
+
const added = (from) => keys.push({
|
|
5717
|
+
from,
|
|
5689
5718
|
columns
|
|
5690
|
-
};
|
|
5719
|
+
});
|
|
5720
|
+
if (addVariantInOwnTable(t, {
|
|
5721
|
+
relation,
|
|
5722
|
+
relatedCollection
|
|
5723
|
+
}, {
|
|
5724
|
+
...mutation,
|
|
5725
|
+
data: [row]
|
|
5726
|
+
}, [], added)) return keys;
|
|
5727
|
+
return [{
|
|
5728
|
+
from: nestedCreate(t, related, parseCreateInput(t, related, row, relatedCollection), [], "rows", mutation.variant),
|
|
5729
|
+
columns
|
|
5730
|
+
}];
|
|
5691
5731
|
}
|
|
5692
5732
|
const [criterion] = mutation.criteria;
|
|
5693
5733
|
if (criterion === void 0) throw ormError("ORM.RELATION_MUTATION_INVALID", `connect() nested mutation for relation "${name}" requires criterion`, { meta: {
|
|
@@ -5695,10 +5735,10 @@ function addParentOwned(t, model, { name, relation, relatedCollection }, mutatio
|
|
|
5695
5735
|
relation: name,
|
|
5696
5736
|
problem: "missing-criterion"
|
|
5697
5737
|
} });
|
|
5698
|
-
return {
|
|
5738
|
+
return [{
|
|
5699
5739
|
from: addFindAndAssert(t, related, name, "connect", criterion, columns),
|
|
5700
5740
|
columns
|
|
5701
|
-
};
|
|
5741
|
+
}];
|
|
5702
5742
|
}
|
|
5703
5743
|
function addChildOwned(t, model, parent, { name, relation, relatedCollection }, mutation) {
|
|
5704
5744
|
const { context } = t;
|
|
@@ -5715,12 +5755,16 @@ function addChildOwned(t, model, parent, { name, relation, relatedCollection },
|
|
|
5715
5755
|
from: parent,
|
|
5716
5756
|
columns: fromParent
|
|
5717
5757
|
}];
|
|
5758
|
+
if (addVariantInOwnTable(t, {
|
|
5759
|
+
relation,
|
|
5760
|
+
relatedCollection
|
|
5761
|
+
}, mutation, keys, () => void 0)) return;
|
|
5718
5762
|
const rows = mutation.data.map((row) => parseCreateInput(t, related, row, relatedCollection));
|
|
5719
5763
|
if (rows.some((row) => row.relationMutations.length > 0)) {
|
|
5720
|
-
for (const row of rows) nestedCreate(t, related, row, keys, "count");
|
|
5764
|
+
for (const row of rows) nestedCreate(t, related, row, keys, "count", mutation.variant);
|
|
5721
5765
|
return;
|
|
5722
5766
|
}
|
|
5723
|
-
addChildInserts(t, related, rows.map((row) => row.scalarData), keys);
|
|
5767
|
+
addChildInserts(t, related, mutation.variant, rows.map((row) => row.scalarData), keys);
|
|
5724
5768
|
return;
|
|
5725
5769
|
}
|
|
5726
5770
|
if (mutation.kind === "connect") {
|
|
@@ -5800,7 +5844,11 @@ function addJunctionOwned(t, model, parent, { name, relation, relatedCollection
|
|
|
5800
5844
|
});
|
|
5801
5845
|
};
|
|
5802
5846
|
if (mutation.kind === "create") {
|
|
5803
|
-
|
|
5847
|
+
if (addVariantInOwnTable(t, {
|
|
5848
|
+
relation,
|
|
5849
|
+
relatedCollection
|
|
5850
|
+
}, mutation, [], (base) => addLink(base, void 0))) return;
|
|
5851
|
+
for (const row of mutation.data) addLink(nestedCreate(t, related, parseCreateInput(t, related, row, relatedCollection), [], "rows", mutation.variant), void 0);
|
|
5804
5852
|
return;
|
|
5805
5853
|
}
|
|
5806
5854
|
if (mutation.kind === "connect") {
|
|
@@ -5875,8 +5923,8 @@ function sourcesOf(contract, model, relation, { root, scope }, parent) {
|
|
|
5875
5923
|
}]
|
|
5876
5924
|
};
|
|
5877
5925
|
}
|
|
5878
|
-
function addChildInserts(t, model, rows, keys) {
|
|
5879
|
-
insertRows(t, model, rows.map((row) => createRowOf(t.context, model,
|
|
5926
|
+
function addChildInserts(t, model, variantValue, rows, keys) {
|
|
5927
|
+
insertRows(t, model, rows.map((row) => createRowOf(t.context, model, variantValue, row, void 0)), {
|
|
5880
5928
|
conflict: void 0,
|
|
5881
5929
|
keys,
|
|
5882
5930
|
requires: [],
|
|
@@ -6139,13 +6187,13 @@ function createGraph(collection, parsed) {
|
|
|
6139
6187
|
}));
|
|
6140
6188
|
return b.graph;
|
|
6141
6189
|
}
|
|
6142
|
-
function createAllVariantGraph(collection, variantTable, mti, data) {
|
|
6190
|
+
function createAllVariantGraph(collection, variantTable, mti, data, nested) {
|
|
6143
6191
|
const { context, modelName, state } = collection;
|
|
6144
6192
|
const variantModelName = mti.variant.modelName;
|
|
6145
6193
|
const rows = variantCreateRowsOf(collection, mti, variantTable, data);
|
|
6146
6194
|
const { contract } = context;
|
|
6147
6195
|
const { root } = state.tables;
|
|
6148
|
-
const graph = new Graph(contract);
|
|
6196
|
+
const graph = nested?.graph ?? new Graph(contract);
|
|
6149
6197
|
const keyColumns = resolvePrimaryKeyColumns(contract, root.storage.namespaceId, root.storage.tableName);
|
|
6150
6198
|
const keyMappings = keyColumns.map((column) => [projectTableColumn(contract, root, column), projectTableColumn(contract, variantTable, column)]);
|
|
6151
6199
|
const baseColumns = returningProjection(contract, modelName, root, void 0);
|
|
@@ -6154,9 +6202,13 @@ function createAllVariantGraph(collection, variantTable, mti, data) {
|
|
|
6154
6202
|
operation: "createAll",
|
|
6155
6203
|
modelName
|
|
6156
6204
|
};
|
|
6157
|
-
const joins = rows.
|
|
6205
|
+
const joins = rows.flatMap((row) => {
|
|
6158
6206
|
const baseInsert = new Insert([insertAst(contract, root, [row.base], void 0).withReturning(baseColumns)], owner);
|
|
6159
|
-
const base = graph.add(baseInsert, {
|
|
6207
|
+
const base = graph.add(baseInsert, {
|
|
6208
|
+
payload: (nested?.keys ?? []).map(({ from, columns }) => new PayloadData(from, columns)),
|
|
6209
|
+
state: graph.stateEdgesFor(baseInsert),
|
|
6210
|
+
requires: [...nested?.requires ?? []]
|
|
6211
|
+
});
|
|
6160
6212
|
const variantInsert = new Insert([insertAst(contract, variantTable, [row.variant], void 0).withReturning(variantColumns)], {
|
|
6161
6213
|
operation: "createAll",
|
|
6162
6214
|
modelName: variantModelName
|
|
@@ -6165,10 +6217,14 @@ function createAllVariantGraph(collection, variantTable, mti, data) {
|
|
|
6165
6217
|
payload: [new PayloadData(base, keyMappings)],
|
|
6166
6218
|
state: graph.stateEdgesFor(variantInsert)
|
|
6167
6219
|
});
|
|
6168
|
-
|
|
6220
|
+
if (nested !== void 0) {
|
|
6221
|
+
nested.added(base);
|
|
6222
|
+
return [];
|
|
6223
|
+
}
|
|
6224
|
+
return [graph.add(new CrossJoin(), {
|
|
6169
6225
|
left: new Rows(base, sameColumns(baseColumns)),
|
|
6170
6226
|
right: new Rows(variant, sameColumns(variantColumns))
|
|
6171
|
-
});
|
|
6227
|
+
})];
|
|
6172
6228
|
});
|
|
6173
6229
|
const [only, ...others] = joins;
|
|
6174
6230
|
if (only !== void 0 && others.length === 0) graph.setResult(only);
|
|
@@ -6986,7 +7042,7 @@ var CollectionBase = class CollectionBase {
|
|
|
6986
7042
|
}
|
|
6987
7043
|
async #create(queryable, data) {
|
|
6988
7044
|
const parsed = parseMutationInput(this.contract, this.namespaceId, this.modelName, blindCast(data), this.#relatedCollection);
|
|
6989
|
-
const [created] = await (mtiCreateContextOf(this.#descriptionOptions()) === void 0 ? queryGraph(createGraph(this.#descriptionOptions(), parsed), this.#on(queryable), this.#descriptionOptions()).toArray() : this.#createAllRows([blindCast(data)])(queryable));
|
|
7045
|
+
const [created] = await (mtiCreateContextOf(this.#descriptionOptions()) === void 0 ? queryGraph(createGraph(this.#descriptionOptions(), parsed), this.#on(queryable), this.#descriptionOptions()).toArray() : this.#createAllRows([blindCast(data)], "create()")(queryable));
|
|
6990
7046
|
if (created !== void 0) return created;
|
|
6991
7047
|
throw ormError("ORM.MUTATION_ROW_MISSING", `create() for model "${this.modelName}" did not return a row`, { meta: {
|
|
6992
7048
|
operation: "create",
|
|
@@ -6998,9 +7054,9 @@ var CollectionBase = class CollectionBase {
|
|
|
6998
7054
|
const { options, configureCallback } = splitCreateArguments(optionsOrConfigure, configure);
|
|
6999
7055
|
const conflictSkip = this.#resolveConflictSkip(options, "createAll()");
|
|
7000
7056
|
const annotations = this.#collectAnnotationsFromMeta(configureCallback, "write", "createAll");
|
|
7001
|
-
return streamOrmCall(this.ctx.runtime, this.#writeCall("createAll", annotations, ormResults.rows), this.#createAllRows(data, conflictSkip));
|
|
7057
|
+
return streamOrmCall(this.ctx.runtime, this.#writeCall("createAll", annotations, ormResults.rows), this.#createAllRows(data, "createAll()", conflictSkip));
|
|
7002
7058
|
}
|
|
7003
|
-
#createAllRows(data, conflictSkip) {
|
|
7059
|
+
#createAllRows(data, method, conflictSkip) {
|
|
7004
7060
|
if (data.length === 0) {
|
|
7005
7061
|
const generator = async function* () {};
|
|
7006
7062
|
return () => new AsyncIterableResult(generator());
|
|
@@ -7008,7 +7064,7 @@ var CollectionBase = class CollectionBase {
|
|
|
7008
7064
|
const rows = blindCast(data);
|
|
7009
7065
|
const mtiContext = mtiCreateContextOf(this.#descriptionOptions());
|
|
7010
7066
|
if (mtiContext) {
|
|
7011
|
-
assertReturningCapability(this.contract,
|
|
7067
|
+
assertReturningCapability(this.contract, method);
|
|
7012
7068
|
const variantTable = requireVariantTable(this.state.tables, mtiContext.variant.value);
|
|
7013
7069
|
const graph = createAllVariantGraph(this.#descriptionWithoutIncludes(), variantTable, mtiContext, rows);
|
|
7014
7070
|
return (queryable) => queryGraph(graph, this.#on(queryable), this.#descriptionWithoutIncludes());
|