express-file-cluster 0.9.6 → 0.10.0

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.
Files changed (159) hide show
  1. package/dist/auth/index.cjs +5 -5
  2. package/dist/auth/index.d.cts +1 -1
  3. package/dist/auth/index.d.ts +1 -1
  4. package/dist/auth/index.js +4 -4
  5. package/dist/{chunk-QL6EWT4B.cjs → chunk-4DOHQU6I.cjs} +9 -7
  6. package/dist/chunk-4DOHQU6I.cjs.map +1 -0
  7. package/dist/{chunk-2SETEVMO.js → chunk-7KC2H76D.js} +42 -2
  8. package/dist/chunk-7KC2H76D.js.map +1 -0
  9. package/dist/{chunk-6KHBJOLB.cjs → chunk-7KO4DJRJ.cjs} +7 -7
  10. package/dist/{chunk-6KHBJOLB.cjs.map → chunk-7KO4DJRJ.cjs.map} +1 -1
  11. package/dist/{chunk-45BWAR6P.js → chunk-ATVD2HGC.js} +3 -3
  12. package/dist/{chunk-BBSZLGZW.js → chunk-EGSSZUVO.js} +8 -6
  13. package/dist/chunk-EGSSZUVO.js.map +1 -0
  14. package/dist/{chunk-TI24L4XE.cjs → chunk-GBI77W5T.cjs} +6 -2
  15. package/dist/chunk-GBI77W5T.cjs.map +1 -0
  16. package/dist/{chunk-VWSUQKCJ.cjs → chunk-HBCY7ILD.cjs} +274 -107
  17. package/dist/chunk-HBCY7ILD.cjs.map +1 -0
  18. package/dist/{chunk-RGT4ZVHL.cjs → chunk-KFVFP2Q7.cjs} +45 -5
  19. package/dist/chunk-KFVFP2Q7.cjs.map +1 -0
  20. package/dist/{chunk-TYCYYLLM.cjs → chunk-NKLOE4AK.cjs} +1 -1
  21. package/dist/chunk-NKLOE4AK.cjs.map +1 -0
  22. package/dist/{chunk-OFA7OGN5.js → chunk-PGJQK36V.js} +171 -4
  23. package/dist/chunk-PGJQK36V.js.map +1 -0
  24. package/dist/{chunk-ULWNHN6P.js → chunk-QDEDOHP7.js} +1 -1
  25. package/dist/chunk-QDEDOHP7.js.map +1 -0
  26. package/dist/{chunk-7ZESZG3J.js → chunk-R4XO4SVM.js} +3 -3
  27. package/dist/chunk-R52CUEGT.js +74 -0
  28. package/dist/chunk-R52CUEGT.js.map +1 -0
  29. package/dist/{chunk-HBYSKULC.js → chunk-RAB44UGX.js} +5 -1
  30. package/dist/chunk-RAB44UGX.js.map +1 -0
  31. package/dist/{chunk-7YEX4MQV.cjs → chunk-WBLUGOAG.cjs} +42 -6
  32. package/dist/chunk-WBLUGOAG.cjs.map +1 -0
  33. package/dist/{chunk-FMA76PRH.cjs → chunk-YK4ZM3CA.cjs} +8 -8
  34. package/dist/{chunk-FMA76PRH.cjs.map → chunk-YK4ZM3CA.cjs.map} +1 -1
  35. package/dist/cli/db-runner.cjs +2010 -116
  36. package/dist/cli/db-runner.cjs.map +1 -1
  37. package/dist/cli/db-runner.js +1987 -93
  38. package/dist/cli/db-runner.js.map +1 -1
  39. package/dist/cli/index.cjs +36 -13
  40. package/dist/cli/index.cjs.map +1 -1
  41. package/dist/cli/index.js +33 -10
  42. package/dist/cli/index.js.map +1 -1
  43. package/dist/docs/api-reference/collection.md +44 -1
  44. package/dist/docs/api-reference/ignite.md +9 -0
  45. package/dist/docs/api-reference/types.md +99 -0
  46. package/dist/docs/cli/add.md +1 -1
  47. package/dist/docs/cli/db.md +2 -2
  48. package/dist/docs/core-concepts/background-tasks.md +6 -3
  49. package/dist/docs/getting-started/index.md +2 -1
  50. package/dist/docs/guides/caching.md +32 -1
  51. package/dist/docs/guides/database.md +2 -0
  52. package/dist/docs/guides/feature-matrix.md +58 -0
  53. package/dist/docs/guides/migrations.md +23 -2
  54. package/dist/docs/guides/which-api.md +2 -2
  55. package/dist/docs/index.md +3 -1
  56. package/dist/docs/skills/SKILL.md +1 -1
  57. package/dist/docs/skills/api-surface.md +5 -0
  58. package/dist/docs/skills/tasks-internals.md +4 -3
  59. package/dist/docs/skills/what-not-to-invent.md +4 -3
  60. package/dist/index.cjs +99 -30
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.cts +204 -3
  63. package/dist/index.d.ts +204 -3
  64. package/dist/index.js +76 -7
  65. package/dist/index.js.map +1 -1
  66. package/dist/pgboss-backend-FW42SBSM.js +14 -0
  67. package/dist/pgboss-backend-RVHUBJTU.cjs +14 -0
  68. package/dist/{pgboss-backend-DSO3QTNK.cjs.map → pgboss-backend-RVHUBJTU.cjs.map} +1 -1
  69. package/dist/registry/index.json +13 -1
  70. package/dist/registry/js-mongo/auth.json +1 -1
  71. package/dist/registry/js-mongo/forgot-password.json +1 -1
  72. package/dist/registry/js-mongo-collection/_base.json +1 -0
  73. package/dist/registry/js-mongo-collection/account-security.json +1 -0
  74. package/dist/registry/js-mongo-collection/account-settings.json +1 -0
  75. package/dist/registry/js-mongo-collection/admin-admins.json +1 -0
  76. package/dist/registry/js-mongo-collection/admin-analytics.json +1 -0
  77. package/dist/registry/js-mongo-collection/admin-billing.json +1 -0
  78. package/dist/registry/js-mongo-collection/admin-content.json +1 -0
  79. package/dist/registry/js-mongo-collection/admin-logs.json +1 -0
  80. package/dist/registry/js-mongo-collection/admin-support.json +1 -0
  81. package/dist/registry/js-mongo-collection/admin-system.json +1 -0
  82. package/dist/registry/js-mongo-collection/admin-users.json +1 -0
  83. package/dist/registry/js-mongo-collection/admin.json +1 -0
  84. package/dist/registry/js-mongo-collection/auth.json +1 -0
  85. package/dist/registry/js-mongo-collection/auth@apple.json +1 -0
  86. package/dist/registry/js-mongo-collection/auth@google.json +1 -0
  87. package/dist/registry/js-mongo-collection/billing.json +1 -0
  88. package/dist/registry/js-mongo-collection/email-client.json +1 -0
  89. package/dist/registry/js-mongo-collection/email-verification.json +1 -0
  90. package/dist/registry/js-mongo-collection/files.json +1 -0
  91. package/dist/registry/js-mongo-collection/forgot-password.json +1 -0
  92. package/dist/registry/js-mongo-collection/notifications.json +1 -0
  93. package/dist/registry/js-mongo-collection/support.json +1 -0
  94. package/dist/registry/js-mongo-collection/user-profile.json +1 -0
  95. package/dist/registry/js-pg-model/auth.json +1 -1
  96. package/dist/registry/js-pg-model/forgot-password.json +1 -1
  97. package/dist/registry/js-pg-table/auth.json +1 -1
  98. package/dist/registry/js-pg-table/forgot-password.json +1 -1
  99. package/dist/registry/ts-mongo/auth.json +1 -1
  100. package/dist/registry/ts-mongo/forgot-password.json +1 -1
  101. package/dist/registry/ts-mongo-collection/_base.json +1 -0
  102. package/dist/registry/ts-mongo-collection/account-security.json +1 -0
  103. package/dist/registry/ts-mongo-collection/account-settings.json +1 -0
  104. package/dist/registry/ts-mongo-collection/admin-admins.json +1 -0
  105. package/dist/registry/ts-mongo-collection/admin-analytics.json +1 -0
  106. package/dist/registry/ts-mongo-collection/admin-billing.json +1 -0
  107. package/dist/registry/ts-mongo-collection/admin-content.json +1 -0
  108. package/dist/registry/ts-mongo-collection/admin-logs.json +1 -0
  109. package/dist/registry/ts-mongo-collection/admin-support.json +1 -0
  110. package/dist/registry/ts-mongo-collection/admin-system.json +1 -0
  111. package/dist/registry/ts-mongo-collection/admin-users.json +1 -0
  112. package/dist/registry/ts-mongo-collection/admin.json +1 -0
  113. package/dist/registry/ts-mongo-collection/auth.json +1 -0
  114. package/dist/registry/ts-mongo-collection/auth@apple.json +1 -0
  115. package/dist/registry/ts-mongo-collection/auth@google.json +1 -0
  116. package/dist/registry/ts-mongo-collection/billing.json +1 -0
  117. package/dist/registry/ts-mongo-collection/email-client.json +1 -0
  118. package/dist/registry/ts-mongo-collection/email-verification.json +1 -0
  119. package/dist/registry/ts-mongo-collection/files.json +1 -0
  120. package/dist/registry/ts-mongo-collection/forgot-password.json +1 -0
  121. package/dist/registry/ts-mongo-collection/notifications.json +1 -0
  122. package/dist/registry/ts-mongo-collection/support.json +1 -0
  123. package/dist/registry/ts-mongo-collection/user-profile.json +1 -0
  124. package/dist/registry/ts-pg-model/auth.json +1 -1
  125. package/dist/registry/ts-pg-model/forgot-password.json +1 -1
  126. package/dist/registry/ts-pg-table/auth.json +1 -1
  127. package/dist/registry/ts-pg-table/forgot-password.json +1 -1
  128. package/dist/tasks/index.cjs +4 -2
  129. package/dist/tasks/index.cjs.map +1 -1
  130. package/dist/tasks/index.d.cts +4 -2
  131. package/dist/tasks/index.d.ts +4 -2
  132. package/dist/tasks/index.js +3 -1
  133. package/dist/thread-runner.cjs +8 -0
  134. package/dist/thread-runner.cjs.map +1 -0
  135. package/dist/thread-runner.d.cts +3 -0
  136. package/dist/thread-runner.d.ts +3 -0
  137. package/dist/thread-runner.js +8 -0
  138. package/dist/thread-runner.js.map +1 -0
  139. package/dist/{types-DAsBKVM-.d.cts → types-Bnxvj3l0.d.cts} +7 -1
  140. package/dist/{types-DAsBKVM-.d.ts → types-Bnxvj3l0.d.ts} +7 -1
  141. package/package.json +1 -1
  142. package/dist/chunk-2SETEVMO.js.map +0 -1
  143. package/dist/chunk-7YEX4MQV.cjs.map +0 -1
  144. package/dist/chunk-BBSZLGZW.js.map +0 -1
  145. package/dist/chunk-HBYSKULC.js.map +0 -1
  146. package/dist/chunk-LJNSJFOL.js +0 -38
  147. package/dist/chunk-LJNSJFOL.js.map +0 -1
  148. package/dist/chunk-OFA7OGN5.js.map +0 -1
  149. package/dist/chunk-QL6EWT4B.cjs.map +0 -1
  150. package/dist/chunk-RGT4ZVHL.cjs.map +0 -1
  151. package/dist/chunk-TI24L4XE.cjs.map +0 -1
  152. package/dist/chunk-TYCYYLLM.cjs.map +0 -1
  153. package/dist/chunk-ULWNHN6P.js.map +0 -1
  154. package/dist/chunk-VWSUQKCJ.cjs.map +0 -1
  155. package/dist/pgboss-backend-DSO3QTNK.cjs +0 -14
  156. package/dist/pgboss-backend-I6DFUNRM.js +0 -14
  157. /package/dist/{chunk-45BWAR6P.js.map → chunk-ATVD2HGC.js.map} +0 -0
  158. /package/dist/{chunk-7ZESZG3J.js.map → chunk-R4XO4SVM.js.map} +0 -0
  159. /package/dist/{pgboss-backend-I6DFUNRM.js.map → pgboss-backend-FW42SBSM.js.map} +0 -0
@@ -18,7 +18,7 @@ import {
18
18
  tableNameFor,
19
19
  timestampFields,
20
20
  validateAtPath
21
- } from "./chunk-ULWNHN6P.js";
21
+ } from "./chunk-QDEDOHP7.js";
22
22
  import {
23
23
  countStatement,
24
24
  getLogger,
@@ -992,7 +992,13 @@ function createModel(name, schema, options, native) {
992
992
  plan: (opts) => call((m) => m.plan(opts)),
993
993
  drop: model.drop,
994
994
  findByIds: (ids) => model.find({ id: { $in: ids } }),
995
- pgTarget: () => ({ table: options.collection ?? tableNameFor(name), idKind: "uuid" })
995
+ pgTarget: () => ({ table: options.collection ?? tableNameFor(name), idKind: "uuid" }),
996
+ studio: {
997
+ storage: async () => getDbEngine() === "mongodb" ? (await model.raw()).collection.collectionName : options.collection ?? tableNameFor(name),
998
+ create: (data) => model.create(data),
999
+ update: (id, data) => model.update(id, data),
1000
+ delete: (id) => model.delete(id)
1001
+ }
996
1002
  });
997
1003
  return model;
998
1004
  }
@@ -2702,7 +2708,16 @@ function createTable(name, schema, options = {}) {
2702
2708
  drop: model.drop,
2703
2709
  findByIds: (ids) => model.findMany({ where: { id: { in: ids } } }),
2704
2710
  pgTarget: () => ({ table: rt().tbl.table, idKind: rt().tbl.idKind }),
2705
- tableRuntime: () => rt()
2711
+ tableRuntime: () => rt(),
2712
+ studio: /* @__PURE__ */ (() => {
2713
+ const idOf = (id) => rt().tbl.idKind === "serial" ? Number(id) : rt().tbl.idKind === "bigserial" ? BigInt(id) : id;
2714
+ return {
2715
+ storage: async () => rt().tbl.table,
2716
+ create: (data) => model.create({ data }),
2717
+ update: (id, data) => model.update({ where: { id: idOf(id) }, data }),
2718
+ delete: (id) => model.delete({ where: { id: idOf(id) } })
2719
+ };
2720
+ })()
2706
2721
  });
2707
2722
  return model;
2708
2723
  }
@@ -2710,6 +2725,129 @@ function defineTable(name, schema, options) {
2710
2725
  return createTable(name, schema, options ?? {});
2711
2726
  }
2712
2727
 
2728
+ // src/db/pipeline.ts
2729
+ var Pipeline = class _Pipeline {
2730
+ /** @internal */
2731
+ constructor(run, stages = []) {
2732
+ this.run = run;
2733
+ this.stages = stages;
2734
+ }
2735
+ run;
2736
+ stages;
2737
+ next(...stage) {
2738
+ return new _Pipeline(this.run, [...this.stages, ...stage]);
2739
+ }
2740
+ /** `$match` — same filter vocabulary as `find`. */
2741
+ match(filter) {
2742
+ return this.next({ $match: filter });
2743
+ }
2744
+ sort(spec) {
2745
+ return this.next({ $sort: spec });
2746
+ }
2747
+ skip(n) {
2748
+ return this.next({ $skip: n });
2749
+ }
2750
+ limit(n) {
2751
+ return this.next({ $limit: n });
2752
+ }
2753
+ /** `$sample` — `n` random records. */
2754
+ sample(n) {
2755
+ return this.next({ $sample: { size: n } });
2756
+ }
2757
+ /** `$project` with an inclusion spec: the result has only those fields (and `id`). */
2758
+ project(spec) {
2759
+ return this.next({ $project: spec });
2760
+ }
2761
+ /**
2762
+ * `$unwind` an array field: one result per element, the field holding that element.
2763
+ * `preserveNullAndEmptyArrays` keeps records without elements (the field is then null).
2764
+ */
2765
+ unwind(path, options) {
2766
+ return this.next(
2767
+ options?.preserveNullAndEmptyArrays ? { $unwind: { path, preserveNullAndEmptyArrays: true } } : { $unwind: path }
2768
+ );
2769
+ }
2770
+ /** `$group` — `_id` is `'$field'`, `null` or `{ key: '$field' }`; accumulators are typed. */
2771
+ group(spec) {
2772
+ return this.next({ $group: spec });
2773
+ }
2774
+ /** `$count` — a single `{ [field]: n }` (no result at all when nothing matched). */
2775
+ count(field) {
2776
+ return this.next({ $count: field });
2777
+ }
2778
+ /** `$addFields` / `$set` — say what the new fields are: `addFields<{ total: number }>({ … })`. */
2779
+ addFields(spec) {
2780
+ return this.next({ $addFields: spec });
2781
+ }
2782
+ lookup(a, b) {
2783
+ const idField = (f) => f === "id" ? "_id" : f;
2784
+ if (typeof a === "string") {
2785
+ const field = a;
2786
+ const target2 = b;
2787
+ const isArray = `__efc_isarr_${field.replace(/\./g, "_")}`;
2788
+ return this.next(async () => [
2789
+ { $set: { [isArray]: { $isArray: `$${field}` } } },
2790
+ {
2791
+ $lookup: {
2792
+ from: await collectionOf(target2),
2793
+ localField: field,
2794
+ foreignField: "_id",
2795
+ as: field
2796
+ }
2797
+ },
2798
+ {
2799
+ $set: {
2800
+ [field]: {
2801
+ $cond: [
2802
+ `$${isArray}`,
2803
+ `$${field}`,
2804
+ { $ifNull: [{ $arrayElemAt: [`$${field}`, 0] }, null] }
2805
+ ]
2806
+ }
2807
+ }
2808
+ },
2809
+ { $unset: isArray }
2810
+ ]);
2811
+ }
2812
+ const { from: target, localField, foreignField, as } = a;
2813
+ return this.next(async () => [
2814
+ {
2815
+ $lookup: {
2816
+ from: await collectionOf(target),
2817
+ localField: idField(localField),
2818
+ foreignField: idField(foreignField),
2819
+ as
2820
+ }
2821
+ }
2822
+ ]);
2823
+ }
2824
+ /** Any other stage, with its output type spelled out: `stage<{ … }>({ $facet: … })`. */
2825
+ stage(stage) {
2826
+ return this.next(stage);
2827
+ }
2828
+ /** The stages as plain objects (lookups resolved to collection names). */
2829
+ async toArray() {
2830
+ const out = [];
2831
+ for (const s of this.stages) {
2832
+ if (typeof s === "function") out.push(...await s());
2833
+ else out.push(s);
2834
+ }
2835
+ return out;
2836
+ }
2837
+ async exec() {
2838
+ return await this.run(await this.toArray());
2839
+ }
2840
+ then(onfulfilled, onrejected) {
2841
+ return this.exec().then(onfulfilled, onrejected);
2842
+ }
2843
+ };
2844
+ async function collectionOf(target) {
2845
+ const model = await target.raw();
2846
+ const name = model.collection?.collectionName ?? model.collection?.name;
2847
+ if (!name) throw new Error(`[EFC] lookup: can't find the collection behind ${target.name}`);
2848
+ return name;
2849
+ }
2850
+
2713
2851
  // src/db/collection-model.ts
2714
2852
  function fromBson(value) {
2715
2853
  if (Array.isArray(value)) return value.map(fromBson);
@@ -2794,6 +2932,26 @@ function createCollection(name, schema, options) {
2794
2932
  const s = session();
2795
2933
  return s ? { session: s } : {};
2796
2934
  };
2935
+ const runPipeline = (stages) => guard(async (M) => {
2936
+ let sourceShape = true;
2937
+ const prepared = stages.map((stage) => {
2938
+ const [op] = Object.keys(stage);
2939
+ if (!sourceShape) return stage;
2940
+ if (op === "$match") {
2941
+ const filter = mapFilter(stage["$match"]);
2942
+ return { $match: M.find().cast(M, filter) };
2943
+ }
2944
+ if (op === "$sort") return { $sort: mapSort(stage["$sort"]) };
2945
+ if (op !== "$skip" && op !== "$limit" && op !== "$sample") sourceShape = false;
2946
+ return stage;
2947
+ });
2948
+ const agg = M.aggregate(prepared);
2949
+ const s = session();
2950
+ if (s) agg.session(s);
2951
+ if (options.collation)
2952
+ agg.collation(options.collation);
2953
+ return (await agg).map(toRecord);
2954
+ });
2797
2955
  const guard = async (fn) => {
2798
2956
  const M = await model();
2799
2957
  try {
@@ -2938,6 +3096,8 @@ function createCollection(name, schema, options) {
2938
3096
  agg.collation(options.collation);
2939
3097
  return (await agg).map(toRecord);
2940
3098
  }),
3099
+ pipeline: () => new Pipeline(runPipeline),
3100
+ lookup: (field, target, filter) => new Pipeline(runPipeline).match(filter ?? {}).lookup(field, target).exec(),
2941
3101
  bulkWrite: (ops, opts) => guard(async (M) => {
2942
3102
  if (ops.length === 0) {
2943
3103
  return {
@@ -3025,6 +3185,12 @@ function createCollection(name, schema, options) {
3025
3185
  findByIds: (ids) => model$.find({ _id: { $in: ids } }),
3026
3186
  pgTarget: () => {
3027
3187
  throw new Error(`[EFC] ${name} is a MongoDB collection (defineCollection)`);
3188
+ },
3189
+ studio: {
3190
+ storage: async () => (await model()).collection.collectionName,
3191
+ create: (data) => model$.create(data),
3192
+ update: (id, data) => model$.findByIdAndUpdate(id, data, { returnDocument: "after" }),
3193
+ delete: (id) => model$.findByIdAndDelete(id)
3028
3194
  }
3029
3195
  });
3030
3196
  return model$;
@@ -3057,6 +3223,7 @@ var db = new Proxy({}, {
3057
3223
  });
3058
3224
 
3059
3225
  export {
3226
+ loadMongoose,
3060
3227
  connectMongo,
3061
3228
  defineModel,
3062
3229
  transaction,
@@ -3066,4 +3233,4 @@ export {
3066
3233
  getDbClient,
3067
3234
  db
3068
3235
  };
3069
- //# sourceMappingURL=chunk-OFA7OGN5.js.map
3236
+ //# sourceMappingURL=chunk-PGJQK36V.js.map