@rpcbase/db 0.21.0 → 0.23.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.
@@ -7,7 +7,7 @@ type ExtractModelNamesFromSchemas<TModules> = {
7
7
  type FrameworkModelName = ExtractModelNamesFromSchemas<typeof frameworkSchemas>;
8
8
  type WithoutRbPrefix<TName extends string> = TName extends `RB${string}` ? never : TName;
9
9
  export type TenantModelName<TModules extends ModelModules> = WithoutRbPrefix<ExtractModelNamesFromSchemas<TModules>> | WithoutRbPrefix<FrameworkModelName>;
10
- export type RbModelName = ExtractModelNamesFromSchemas<typeof frameworkSchemas> extends infer Name ? Name extends string ? Name extends `RB${string}` ? Name : never : never : never;
10
+ export type RbModelName = ExtractModelNamesFromSchemas<typeof frameworkSchemas> extends infer Name ? Name extends string ? Name extends `RB${string}` ? Name extends "RBRtsChange" | "RBRtsCounter" | "RBUploadSession" | "RBUploadChunk" ? never : Name : never : never : never;
11
11
  export type ModelsClient<TModules extends ModelModules> = {
12
12
  register: (modules: TModules) => void;
13
13
  get: (modelName: TenantModelName<TModules>, ctx: LoadModelCtx) => ReturnType<typeof loadModel>;
@@ -1 +1 @@
1
- {"version":3,"file":"createModels.d.ts","sourceRoot":"","sources":["../src/createModels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,KAAK,gBAAgB,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAIpD,KAAK,4BAA4B,CAAC,QAAQ,IAAI;KAC3C,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,GAAG,MAAM,IAAI,QAAQ,GAAG,IAAI,GAAG,KAAK;CACxE,CAAC,MAAM,QAAQ,CAAC,GAAG,MAAM,C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,GAAI,QAAQ,SAAS,YAAY,EAAE,SAAS,QAAQ,KAAG,YAAY,CAAC,QAAQ,CAQpG,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { default as mongoose } from '../../vite/node_modules/mongoose';
2
+ export declare const ensureMongooseConnection: (dbName: string) => Promise<mongoose.Connection>;
3
+ //# sourceMappingURL=ensureMongooseConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureMongooseConnection.d.ts","sourceRoot":"","sources":["../src/ensureMongooseConnection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAO/B,eAAO,MAAM,wBAAwB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CA0B1F,CAAA"}
@@ -0,0 +1,6 @@
1
+ type EnvRecord = {
2
+ [key: string]: string | undefined;
3
+ };
4
+ export declare const getMongoUrl: (env?: EnvRecord) => string;
5
+ export {};
6
+ //# sourceMappingURL=getMongoUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMongoUrl.d.ts","sourceRoot":"","sources":["../src/getMongoUrl.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAEtD,eAAO,MAAM,WAAW,GAAI,MAAK,SAAuB,KAAG,MAgB1D,CAAA"}
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './models';
2
2
  export * from './schema';
3
3
  export * from './createModels';
4
4
  export * from './loadModel';
5
+ export * from './tenantFilesystemDb';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -31,38 +31,124 @@ const RBTenantSchema = new Schema({
31
31
  parent_tenant_id: { type: String },
32
32
  name: { type: String }
33
33
  }, { collection: "tenants" });
34
- const RtsCounterSchema = new Schema(
34
+ const ZRBRtsCounter = z.object({
35
+ _id: z.string(),
36
+ seq: z.number().int().min(0)
37
+ });
38
+ const RBRtsCounterSchema = new Schema(
35
39
  {
36
40
  _id: { type: String, required: true },
37
41
  seq: { type: Number, required: true, default: 0 }
38
42
  },
39
43
  {
40
- versionKey: false
44
+ versionKey: false,
45
+ collection: "rtscounters"
41
46
  }
42
47
  );
43
48
  const ttlSecondsRaw = process.env.RB_RTS_CHANGES_TTL_S ?? "";
44
49
  const ttlSeconds = Number.isFinite(Number(ttlSecondsRaw)) ? Math.max(60, Math.floor(Number(ttlSecondsRaw))) : 60 * 60 * 24 * 30;
45
- const RtsChangeSchema = new Schema(
50
+ const ZRBRtsChangeOp = z.enum(["delete", "reset_model"]);
51
+ const ZRBRtsChange = z.object({
52
+ seq: z.number().int().min(0),
53
+ modelName: z.string(),
54
+ op: ZRBRtsChangeOp,
55
+ docId: z.string().optional(),
56
+ ts: z.date()
57
+ });
58
+ const RBRtsChangeSchema = new Schema(
46
59
  {
47
60
  seq: { type: Number, required: true },
48
61
  modelName: { type: String, required: true, index: true },
49
- op: { type: String, required: true, enum: ["delete", "reset_model"] },
62
+ op: { type: String, required: true, enum: ZRBRtsChangeOp.options },
50
63
  docId: { type: String, required: false },
51
64
  ts: { type: Date, required: true, default: Date.now }
52
65
  },
53
66
  {
54
- versionKey: false
67
+ versionKey: false,
68
+ collection: "rtschanges"
69
+ }
70
+ );
71
+ RBRtsChangeSchema.index({ seq: 1 }, { unique: true });
72
+ RBRtsChangeSchema.index({ ts: 1 }, { expireAfterSeconds: ttlSeconds });
73
+ const ZRBUploadSessionStatus = z.enum(["uploading", "assembling", "done", "error"]);
74
+ const ZRBUploadSession = z.object({
75
+ _id: z.string(),
76
+ userId: z.string().optional(),
77
+ ownerKeyHash: z.string().optional(),
78
+ filename: z.string(),
79
+ mimeType: z.string(),
80
+ totalSize: z.number().int().min(0),
81
+ chunkSize: z.number().int().min(1),
82
+ chunksTotal: z.number().int().min(1),
83
+ status: ZRBUploadSessionStatus,
84
+ createdAt: z.date(),
85
+ expiresAt: z.date(),
86
+ fileId: z.string().optional(),
87
+ error: z.string().optional()
88
+ });
89
+ const RBUploadSessionSchema = new Schema(
90
+ {
91
+ _id: { type: String, required: true },
92
+ userId: { type: String, required: false, index: true },
93
+ ownerKeyHash: { type: String, required: false },
94
+ filename: { type: String, required: true },
95
+ mimeType: { type: String, required: true },
96
+ totalSize: { type: Number, required: true },
97
+ chunkSize: { type: Number, required: true },
98
+ chunksTotal: { type: Number, required: true },
99
+ status: { type: String, required: true, enum: ZRBUploadSessionStatus.options },
100
+ createdAt: { type: Date, required: true, default: Date.now },
101
+ expiresAt: { type: Date, required: true },
102
+ fileId: { type: String, required: false },
103
+ error: { type: String, required: false }
104
+ },
105
+ {
106
+ versionKey: false,
107
+ collection: "uploadSessions"
108
+ }
109
+ );
110
+ RBUploadSessionSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
111
+ const ZRBUploadChunk = z.object({
112
+ uploadId: z.string(),
113
+ index: z.number().int().min(0),
114
+ data: z.any(),
115
+ size: z.number().int().min(0),
116
+ sha256: z.string().optional(),
117
+ createdAt: z.date(),
118
+ expiresAt: z.date()
119
+ });
120
+ const RBUploadChunkSchema = new Schema(
121
+ {
122
+ uploadId: { type: String, required: true, index: true },
123
+ index: { type: Number, required: true },
124
+ data: { type: Buffer, required: true },
125
+ size: { type: Number, required: true },
126
+ sha256: { type: String, required: false },
127
+ createdAt: { type: Date, required: true, default: Date.now },
128
+ expiresAt: { type: Date, required: true }
129
+ },
130
+ {
131
+ versionKey: false,
132
+ collection: "uploadChunks"
55
133
  }
56
134
  );
57
- RtsChangeSchema.index({ seq: 1 }, { unique: true });
58
- RtsChangeSchema.index({ ts: 1 }, { expireAfterSeconds: ttlSeconds });
135
+ RBUploadChunkSchema.index({ uploadId: 1, index: 1 }, { unique: true });
136
+ RBUploadChunkSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
59
137
  const frameworkSchemas = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
60
138
  __proto__: null,
139
+ RBRtsChangeSchema,
140
+ RBRtsCounterSchema,
61
141
  RBTenantSchema,
142
+ RBUploadChunkSchema,
143
+ RBUploadSessionSchema,
62
144
  RBUserSchema,
63
- RtsChangeSchema,
64
- RtsCounterSchema,
145
+ ZRBRtsChange,
146
+ ZRBRtsChangeOp,
147
+ ZRBRtsCounter,
65
148
  ZRBTenant,
149
+ ZRBUploadChunk,
150
+ ZRBUploadSession,
151
+ ZRBUploadSessionStatus,
66
152
  ZRBUser
67
153
  }, Symbol.toStringTag, { value: "Module" }));
68
154
  const zmAssert$4 = {
@@ -778,8 +864,42 @@ function parseMixed(required = true, def) {
778
864
  required
779
865
  };
780
866
  }
867
+ const getMongoUrl = (env = process.env) => {
868
+ const explicitUrl = env.MONGODB_URL ?? env.MONGO_URL ?? env.MONGODB_URI ?? env.DB_URL;
869
+ if (explicitUrl && explicitUrl.trim()) {
870
+ return explicitUrl.trim();
871
+ }
872
+ const port = env.DB_PORT?.trim();
873
+ if (!port) throw new Error("Missing Mongo connection details (MONGODB_URL/MONGO_URL/MONGODB_URI/DB_URL/DB_PORT)");
874
+ const host = env.DB_HOST?.trim() || "localhost";
875
+ return `mongodb://${host}:${port}`;
876
+ };
877
+ const connections = {};
878
+ const ensureMongooseConnection = async (dbName) => {
879
+ const mongoUrl = getMongoUrl();
880
+ if (!connections[dbName]) {
881
+ const connection = mongoose.createConnection(mongoUrl, {
882
+ sanitizeFilter: true,
883
+ dbName
884
+ });
885
+ await new Promise((resolve, reject) => {
886
+ connection.once("open", resolve);
887
+ connection.on("error", reject);
888
+ });
889
+ connections[dbName] = connection;
890
+ } else {
891
+ const connection = connections[dbName];
892
+ if (connection.readyState !== 1) {
893
+ await new Promise((resolve, reject) => {
894
+ connection.once("open", resolve);
895
+ connection.on("error", reject);
896
+ });
897
+ }
898
+ }
899
+ return connections[dbName];
900
+ };
781
901
  const RTS_COUNTER_ID = "rts";
782
- const EXCLUDED_MODEL_NAMES = /* @__PURE__ */ new Set(["RtsChange", "RtsCounter"]);
902
+ const EXCLUDED_MODEL_NAMES = /* @__PURE__ */ new Set(["RBRtsChange", "RBRtsCounter"]);
783
903
  const maxDeleteIdsRaw = process.env.RB_RTS_DELETE_LOG_MAX_IDS ?? "";
784
904
  const maxDeleteIds = Number.isFinite(Number(maxDeleteIdsRaw)) ? Math.max(1, Math.floor(Number(maxDeleteIdsRaw))) : 5e3;
785
905
  const deleteMetaByQuery = /* @__PURE__ */ new WeakMap();
@@ -802,8 +922,8 @@ const getDbName = (db) => {
802
922
  };
803
923
  const isUsersDb = (db) => getDbName(db).endsWith("-users-db");
804
924
  const getRtsModels = (db) => {
805
- const RtsCounter = db.models.RtsCounter ?? db.model("RtsCounter", RtsCounterSchema);
806
- const RtsChange = db.models.RtsChange ?? db.model("RtsChange", RtsChangeSchema);
925
+ const RtsCounter = db.models.RBRtsCounter ?? db.model("RBRtsCounter", RBRtsCounterSchema);
926
+ const RtsChange = db.models.RBRtsChange ?? db.model("RBRtsChange", RBRtsChangeSchema);
807
927
  return { RtsCounter, RtsChange };
808
928
  };
809
929
  const allocateSeqRange = async (db, count) => {
@@ -910,7 +1030,7 @@ const rtsChangeLogPlugin = (schema) => {
910
1030
  }
911
1031
  });
912
1032
  };
913
- const RTS_CHANGELOG_EXCLUDED_MODELS = /* @__PURE__ */ new Set(["RtsChange", "RtsCounter"]);
1033
+ const RTS_CHANGELOG_EXCLUDED_MODELS = /* @__PURE__ */ new Set(["RBRtsChange", "RBRtsCounter"]);
914
1034
  const rtsChangeLogApplied = /* @__PURE__ */ new WeakSet();
915
1035
  let cachedModels = null;
916
1036
  const isRtsChangelogExcludedModelName = (name) => name.startsWith("RB") || RTS_CHANGELOG_EXCLUDED_MODELS.has(name);
@@ -969,9 +1089,15 @@ const getRegisteredModels = () => {
969
1089
  }
970
1090
  return cachedModels;
971
1091
  };
972
- const { APP_NAME, DB_PORT } = process.env;
973
- const connections = {};
1092
+ const { APP_NAME } = process.env;
1093
+ const TENANT_INTERNAL_MODEL_NAMES = /* @__PURE__ */ new Set([
1094
+ "RBRtsChange",
1095
+ "RBRtsCounter",
1096
+ "RBUploadSession",
1097
+ "RBUploadChunk"
1098
+ ]);
974
1099
  const assertTenantModelName = (modelName) => {
1100
+ if (TENANT_INTERNAL_MODEL_NAMES.has(modelName)) return;
975
1101
  assert(
976
1102
  !modelName.startsWith("RB"),
977
1103
  "Invalid tenant model name. RB* models are stored in the global users DB; use loadRbModel."
@@ -979,34 +1105,13 @@ const assertTenantModelName = (modelName) => {
979
1105
  };
980
1106
  const assertRbModelName = (modelName) => {
981
1107
  assert(modelName.startsWith("RB"), "Invalid RB model name. Supported: RB*");
982
- };
983
- const ensureConnection = async (dbName) => {
984
- const connectionString = `mongodb://localhost:${DB_PORT}/${dbName}`;
985
- if (!connections[dbName]) {
986
- const connection = mongoose.createConnection(connectionString, {
987
- sanitizeFilter: true
988
- });
989
- await new Promise((resolve, reject) => {
990
- connection.once("open", resolve);
991
- connection.on("error", reject);
992
- });
993
- connections[dbName] = connection;
994
- } else {
995
- const connection = connections[dbName];
996
- if (connection.readyState !== 1) {
997
- await new Promise((resolve, reject) => {
998
- connection.once("open", resolve);
999
- connection.on("error", reject);
1000
- });
1001
- }
1002
- }
1003
- return connections[dbName];
1108
+ assert(!TENANT_INTERNAL_MODEL_NAMES.has(modelName), "Invalid RB model name. Use loadModel for tenant-scoped RB* models.");
1004
1109
  };
1005
1110
  const loadModelFromDb = async (modelName, dbName) => {
1006
1111
  const models = getRegisteredModels();
1007
1112
  const model = models[modelName];
1008
1113
  assert(model, `Model ${modelName} not registered. Available models: ${Object.keys(models).join(", ")}`);
1009
- const modelConnection = await ensureConnection(dbName);
1114
+ const modelConnection = await ensureMongooseConnection(dbName);
1010
1115
  if (!modelConnection.models[modelName]) {
1011
1116
  modelConnection.model(modelName, model.schema);
1012
1117
  }
@@ -1032,17 +1137,45 @@ const createModels = (modules) => {
1032
1137
  getRb: (modelName, ctx) => loadRbModel(modelName)
1033
1138
  };
1034
1139
  };
1140
+ const getAppName = () => {
1141
+ const appName = process.env.APP_NAME?.trim();
1142
+ assert(appName, "Missing APP_NAME");
1143
+ return appName;
1144
+ };
1145
+ const normalizeTenantId = (tenantId) => {
1146
+ const normalized = tenantId.trim();
1147
+ assert(normalized, "Tenant ID is missing");
1148
+ return normalized;
1149
+ };
1150
+ const getTenantFilesystemDbName = (tenantId) => `${getAppName()}-${normalizeTenantId(tenantId)}-filesystem-db`;
1151
+ const getTenantFilesystemDb = async (tenantId) => ensureMongooseConnection(getTenantFilesystemDbName(tenantId));
1152
+ const getTenantFilesystemDbFromCtx = async (ctx) => {
1153
+ const tenantId = ctx.req.session?.user?.current_tenant_id;
1154
+ assert(typeof tenantId === "string" && tenantId.trim(), "Tenant ID is missing from session");
1155
+ return getTenantFilesystemDb(tenantId);
1156
+ };
1035
1157
  export {
1036
1158
  LANGUAGE_CODE_REGEX,
1159
+ RBRtsChangeSchema,
1160
+ RBRtsCounterSchema,
1037
1161
  RBTenantSchema,
1162
+ RBUploadChunkSchema,
1163
+ RBUploadSessionSchema,
1038
1164
  RBUserSchema,
1039
- RtsChangeSchema,
1040
- RtsCounterSchema,
1165
+ ZRBRtsChange,
1166
+ ZRBRtsChangeOp,
1167
+ ZRBRtsCounter,
1041
1168
  ZRBTenant,
1169
+ ZRBUploadChunk,
1170
+ ZRBUploadSession,
1171
+ ZRBUploadSessionStatus,
1042
1172
  ZRBUser,
1043
1173
  buildLocaleFallbackChain,
1044
1174
  createModels,
1045
1175
  extendZod,
1176
+ getTenantFilesystemDb,
1177
+ getTenantFilesystemDbFromCtx,
1178
+ getTenantFilesystemDbName,
1046
1179
  loadModel,
1047
1180
  loadRbModel,
1048
1181
  resolveLocalizedString,
@@ -1 +1 @@
1
- {"version":3,"file":"loadModel.d.ts","sourceRoot":"","sources":["../src/loadModel.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAK/B,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE;QACH,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,EAAE;gBACL,iBAAiB,CAAC,EAAE,MAAM,CAAC;aAC5B,CAAA;SACF,GAAG,IAAI,CAAC;KACV,CAAC;CACH,CAAC;AAyDF,eAAO,MAAM,SAAS,GAAU,WAAW,MAAM,EAAE,KAAK,YAAY,4DAOnE,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,WAAW,MAAM,EAAE,MAAM,YAAY,4DAItE,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"loadModel.d.ts","sourceRoot":"","sources":["../src/loadModel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAMpC,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE;QACH,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,EAAE;gBACL,iBAAiB,CAAC,EAAE,MAAM,CAAC;aAC5B,CAAA;SACF,GAAG,IAAI,CAAC;KACV,CAAC;CACH,CAAC;AAuCF,eAAO,MAAM,SAAS,GAAU,WAAW,MAAM,EAAE,KAAK,YAAY,4DAOnE,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,WAAW,MAAM,EAAE,MAAM,YAAY,4DAItE,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBRtsChangeOp: z.ZodEnum<{
4
+ delete: "delete";
5
+ reset_model: "reset_model";
6
+ }>;
7
+ export declare const ZRBRtsChange: z.ZodObject<{
8
+ seq: z.ZodNumber;
9
+ modelName: z.ZodString;
10
+ op: z.ZodEnum<{
11
+ delete: "delete";
12
+ reset_model: "reset_model";
13
+ }>;
14
+ docId: z.ZodOptional<z.ZodString>;
15
+ ts: z.ZodDate;
16
+ }, z.core.$strip>;
17
+ export type IRBRtsChange = z.infer<typeof ZRBRtsChange>;
18
+ export declare const RBRtsChangeSchema: Schema;
19
+ //# sourceMappingURL=RBRtsChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBRtsChange.d.ts","sourceRoot":"","sources":["../../src/models/RBRtsChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,cAAc;;;EAAoC,CAAA;AAE/D,eAAO,MAAM,YAAY;;;;;;;;;iBAMvB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEvD,eAAO,MAAM,iBAAiB,EAAE,MAY/B,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBRtsCounter: z.ZodObject<{
4
+ _id: z.ZodString;
5
+ seq: z.ZodNumber;
6
+ }, z.core.$strip>;
7
+ export type IRBRtsCounter = z.infer<typeof ZRBRtsCounter>;
8
+ export declare const RBRtsCounterSchema: Schema;
9
+ //# sourceMappingURL=RBRtsCounter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBRtsCounter.d.ts","sourceRoot":"","sources":["../../src/models/RBRtsCounter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,aAAa;;;iBAGxB,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEzD,eAAO,MAAM,kBAAkB,EAAE,MAShC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBUploadChunk: z.ZodObject<{
4
+ uploadId: z.ZodString;
5
+ index: z.ZodNumber;
6
+ data: z.ZodAny;
7
+ size: z.ZodNumber;
8
+ sha256: z.ZodOptional<z.ZodString>;
9
+ createdAt: z.ZodDate;
10
+ expiresAt: z.ZodDate;
11
+ }, z.core.$strip>;
12
+ export type IRBUploadChunk = z.infer<typeof ZRBUploadChunk>;
13
+ export declare const RBUploadChunkSchema: Schema;
14
+ //# sourceMappingURL=RBUploadChunk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBUploadChunk.d.ts","sourceRoot":"","sources":["../../src/models/RBUploadChunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,cAAc;;;;;;;;iBAQzB,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAE3D,eAAO,MAAM,mBAAmB,EAAE,MAcjC,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBUploadSessionStatus: z.ZodEnum<{
4
+ error: "error";
5
+ done: "done";
6
+ uploading: "uploading";
7
+ assembling: "assembling";
8
+ }>;
9
+ export declare const ZRBUploadSession: z.ZodObject<{
10
+ _id: z.ZodString;
11
+ userId: z.ZodOptional<z.ZodString>;
12
+ ownerKeyHash: z.ZodOptional<z.ZodString>;
13
+ filename: z.ZodString;
14
+ mimeType: z.ZodString;
15
+ totalSize: z.ZodNumber;
16
+ chunkSize: z.ZodNumber;
17
+ chunksTotal: z.ZodNumber;
18
+ status: z.ZodEnum<{
19
+ error: "error";
20
+ done: "done";
21
+ uploading: "uploading";
22
+ assembling: "assembling";
23
+ }>;
24
+ createdAt: z.ZodDate;
25
+ expiresAt: z.ZodDate;
26
+ fileId: z.ZodOptional<z.ZodString>;
27
+ error: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ export type IRBUploadSession = z.infer<typeof ZRBUploadSession>;
30
+ export declare const RBUploadSessionSchema: Schema;
31
+ //# sourceMappingURL=RBUploadSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBUploadSession.d.ts","sourceRoot":"","sources":["../../src/models/RBUploadSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,sBAAsB;;;;;EAAuD,CAAA;AAE1F,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;iBAc3B,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAE/D,eAAO,MAAM,qBAAqB,EAAE,MAoBnC,CAAA"}
@@ -1,5 +1,7 @@
1
1
  export * from './User';
2
2
  export * from './Tenant';
3
- export * from './RtsCounter';
4
- export * from './RtsChange';
3
+ export * from './RBRtsCounter';
4
+ export * from './RBRtsChange';
5
+ export * from './RBUploadSession';
6
+ export * from './RBUploadChunk';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"rtsChangeLogPlugin.d.ts","sourceRoot":"","sources":["../src/rtsChangeLogPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AA4KpC,eAAO,MAAM,kBAAkB,GAAI,QAAQ,QAAQ,CAAC,MAAM,KAAG,IAkC5D,CAAA"}
1
+ {"version":3,"file":"rtsChangeLogPlugin.d.ts","sourceRoot":"","sources":["../src/rtsChangeLogPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAkKpC,eAAO,MAAM,kBAAkB,GAAI,QAAQ,QAAQ,CAAC,MAAM,KAAG,IAkC5D,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { default as mongoose } from '../../vite/node_modules/mongoose';
2
+ import { LoadModelCtx } from './loadModel';
3
+ export declare const getTenantFilesystemDbName: (tenantId: string) => string;
4
+ export declare const getTenantFilesystemDb: (tenantId: string) => Promise<mongoose.Connection>;
5
+ export declare const getTenantFilesystemDbFromCtx: (ctx: LoadModelCtx) => Promise<mongoose.Connection>;
6
+ //# sourceMappingURL=tenantFilesystemDb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenantFilesystemDb.d.ts","sourceRoot":"","sources":["../src/tenantFilesystemDb.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAe/C,eAAO,MAAM,yBAAyB,GAAI,UAAU,MAAM,KAAG,MACG,CAAA;AAEhE,eAAO,MAAM,qBAAqB,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAC3B,CAAA;AAE/D,eAAO,MAAM,4BAA4B,GAAU,KAAK,YAAY,KAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIjG,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/db",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,3 +0,0 @@
1
- import { Schema } from '../../../vite/node_modules/mongoose';
2
- export declare const RtsChangeSchema: Schema;
3
- //# sourceMappingURL=RtsChange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RtsChange.d.ts","sourceRoot":"","sources":["../../src/models/RtsChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAMjC,eAAO,MAAM,eAAe,EAAE,MAW7B,CAAA"}
@@ -1,3 +0,0 @@
1
- import { Schema } from '../../../vite/node_modules/mongoose';
2
- export declare const RtsCounterSchema: Schema;
3
- //# sourceMappingURL=RtsCounter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RtsCounter.d.ts","sourceRoot":"","sources":["../../src/models/RtsCounter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,eAAO,MAAM,gBAAgB,EAAE,MAQ9B,CAAA"}