@ragestudio/scylla-odm 0.10.0 → 0.10.2

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 (79) hide show
  1. package/{client.d.mts → client.d.ts} +3 -3
  2. package/{client.mjs → client.js} +4 -4
  3. package/client.js.map +1 -0
  4. package/cql_gen/{create_table.d.mts → create_table.d.ts} +2 -2
  5. package/cql_gen/{create_table.mjs → create_table.js} +1 -1
  6. package/cql_gen/create_table.js.map +1 -0
  7. package/index.d.ts +6 -0
  8. package/index.js +11 -0
  9. package/index.js.map +1 -0
  10. package/model/{index.d.mts → index.d.ts} +6 -6
  11. package/model/{index.mjs → index.js} +10 -10
  12. package/model/index.js.map +1 -0
  13. package/operations/{countAll.d.mts → countAll.d.ts} +2 -2
  14. package/operations/{countAll.mjs → countAll.js} +1 -1
  15. package/operations/countAll.js.map +1 -0
  16. package/operations/{delete.d.mts → delete.d.ts} +2 -2
  17. package/operations/{delete.mjs → delete.js} +1 -1
  18. package/operations/delete.js.map +1 -0
  19. package/operations/{find.d.mts → find.d.ts} +3 -3
  20. package/operations/{find.mjs → find.js} +2 -2
  21. package/operations/find.js.map +1 -0
  22. package/operations/{findOne.d.mts → findOne.d.ts} +3 -3
  23. package/operations/{findOne.mjs → findOne.js} +2 -2
  24. package/operations/findOne.js.map +1 -0
  25. package/operations/{sync.d.mts → sync.d.ts} +2 -2
  26. package/operations/{sync.mjs → sync.js} +2 -2
  27. package/operations/sync.js.map +1 -0
  28. package/operations/{tableExists.d.mts → tableExists.d.ts} +2 -2
  29. package/operations/{tableExists.mjs → tableExists.js} +1 -1
  30. package/operations/tableExists.js.map +1 -0
  31. package/operations/{update.d.mts → update.d.ts} +2 -2
  32. package/operations/{update.mjs → update.js} +3 -3
  33. package/operations/update.js.map +1 -0
  34. package/package.json +3 -3
  35. package/result/{index.d.mts → index.d.ts} +3 -3
  36. package/result/{index.mjs → index.js} +2 -2
  37. package/result/index.js.map +1 -0
  38. package/schema/{index.d.mts → index.d.ts} +2 -2
  39. package/schema/{index.mjs → index.js} +1 -1
  40. package/schema/index.js.map +1 -0
  41. package/{types.d.mts → types.d.ts} +3 -3
  42. package/{types.mjs → types.js} +1 -1
  43. package/types.js.map +1 -0
  44. package/utils/{buildMapper.d.mts → buildMapper.d.ts} +1 -1
  45. package/utils/{buildMapper.mjs → buildMapper.js} +1 -1
  46. package/utils/buildMapper.js.map +1 -0
  47. package/utils/{fillDefaults.d.mts → fillDefaults.d.ts} +1 -1
  48. package/utils/{fillDefaults.mjs → fillDefaults.js} +1 -1
  49. package/utils/fillDefaults.js.map +1 -0
  50. package/utils/{loadModels.d.mts → loadModels.d.ts} +1 -1
  51. package/utils/{loadModels.mjs → loadModels.js} +1 -1
  52. package/utils/loadModels.js.map +1 -0
  53. package/utils/{queryParser.d.mts → queryParser.d.ts} +2 -2
  54. package/utils/{queryParser.mjs → queryParser.js} +1 -1
  55. package/utils/queryParser.js.map +1 -0
  56. package/utils/{typeChecker.d.mts → typeChecker.d.ts} +2 -2
  57. package/utils/{typeChecker.mjs → typeChecker.js} +2 -2
  58. package/utils/typeChecker.js.map +1 -0
  59. package/client.mjs.map +0 -1
  60. package/cql_gen/create_table.mjs.map +0 -1
  61. package/index.d.mts +0 -6
  62. package/index.mjs +0 -11
  63. package/index.mjs.map +0 -1
  64. package/model/index.mjs.map +0 -1
  65. package/operations/countAll.mjs.map +0 -1
  66. package/operations/delete.mjs.map +0 -1
  67. package/operations/find.mjs.map +0 -1
  68. package/operations/findOne.mjs.map +0 -1
  69. package/operations/sync.mjs.map +0 -1
  70. package/operations/tableExists.mjs.map +0 -1
  71. package/operations/update.mjs.map +0 -1
  72. package/result/index.mjs.map +0 -1
  73. package/schema/index.mjs.map +0 -1
  74. package/types.mjs.map +0 -1
  75. package/utils/buildMapper.mjs.map +0 -1
  76. package/utils/fillDefaults.mjs.map +0 -1
  77. package/utils/loadModels.mjs.map +0 -1
  78. package/utils/queryParser.mjs.map +0 -1
  79. package/utils/typeChecker.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { Model } from "./model/index.mjs";
2
- import { ClientConfig } from "./types.mjs";
1
+ import { Model } from "./model/index.js";
2
+ import { ClientConfig } from "./types.js";
3
3
  import { Client as Client$1, mapping } from "cassandra-driver";
4
4
 
5
5
  //#region src/client.d.ts
@@ -20,4 +20,4 @@ declare class Client {
20
20
  }
21
21
  //#endregion
22
22
  export { Client, Client as default };
23
- //# sourceMappingURL=client.d.mts.map
23
+ //# sourceMappingURL=client.d.ts.map
@@ -1,6 +1,6 @@
1
- import loadModels_default from "./utils/loadModels.mjs";
2
- import buildMapper_default from "./utils/buildMapper.mjs";
3
- import { Model } from "./model/index.mjs";
1
+ import loadModels_default from "./utils/loadModels.js";
2
+ import buildMapper_default from "./utils/buildMapper.js";
3
+ import { Model } from "./model/index.js";
4
4
  import path from "node:path";
5
5
  import Cassandra from "cassandra-driver";
6
6
  //#region src/client.ts
@@ -111,4 +111,4 @@ var Client = class {
111
111
  //#endregion
112
112
  export { Client, Client as default };
113
113
 
114
- //# sourceMappingURL=client.mjs.map
114
+ //# sourceMappingURL=client.js.map
package/client.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":["loadModels","buildMapper"],"sources":["../src/client.ts"],"sourcesContent":["import type {\n\tClient as T_CassandraClient,\n\tClientOptions as T_CassandraClientOptions,\n\tmapping as T_CassandraMapping,\n} from \"cassandra-driver\"\nimport type { ClientConfig } from \"./types\"\n\n//@ts-ignore\nimport path from \"node:path\"\n//@ts-ignore\nimport Cassandra from \"cassandra-driver\"\nimport loadModels from \"./utils/loadModels\"\nimport buildMapper from \"./utils/buildMapper\"\n\nimport { Model } from \"./model\"\nimport { InferDocument } from \"./types\"\n\nconst DEFAULT_MAX_RETRIES = 3\nconst DEFAULT_RETRY_DELAY = 1000\nconst { SCYLLA_CONTACT_POINTS, SCYLLA_LOCAL_DATA_CENTER, SCYLLA_KEYSPACE } =\n\tprocess.env\n\nexport class Client {\n\tconstructor(config: ClientConfig = {}) {\n\t\tif (globalThis.__scylla_client) {\n\t\t\tthrow new Error(\n\t\t\t\t\"An instance of Scylla Client is already initialized\",\n\t\t\t)\n\t\t}\n\n\t\tthis.config = {\n\t\t\tmodelsPath: path.resolve(process.cwd(), \"db\"),\n\t\t\tcontactPoints:\n\t\t\t\t(config.contactPoints ?? SCYLLA_CONTACT_POINTS)\n\t\t\t\t\t? SCYLLA_CONTACT_POINTS.split(\",\")\n\t\t\t\t\t: [\"127.0.0.1\"],\n\t\t\tlocalDataCenter:\n\t\t\t\tconfig.localDataCenter ??\n\t\t\t\tSCYLLA_LOCAL_DATA_CENTER ??\n\t\t\t\t\"datacenter1\",\n\t\t\tkeyspace: config.keyspace ?? SCYLLA_KEYSPACE ?? \"default\",\n\t\t\tport: 9042,\n\t\t\tmaxRetries: DEFAULT_MAX_RETRIES,\n\t\t\tretryDelay: DEFAULT_RETRY_DELAY,\n\t\t\t...config,\n\t\t}\n\n\t\tconst clientOptions: T_CassandraClientOptions = {\n\t\t\tcontactPoints: this.config.contactPoints,\n\t\t\tlocalDataCenter: this.config.localDataCenter,\n\t\t\tkeyspace: this.config.keyspace,\n\t\t\tprotocolOptions: {\n\t\t\t\tport: this.config.port,\n\t\t\t},\n\t\t}\n\n\t\tif (this.config.pooling) {\n\t\t\tclientOptions.pooling = this.config.pooling\n\t\t}\n\n\t\tthis.driver = new Cassandra.Client(clientOptions)\n\t}\n\n\tconfig: ClientConfig\n\tdriver: T_CassandraClient\n\tmapper: T_CassandraMapping.Mapper\n\tmodels: Map<string, Model<any>> = new Map()\n\n\tasync initialize(options: { sync?: boolean } = {}) {\n\t\tlet models: Model<any>[]\n\n\t\ttry {\n\t\t\tmodels = await loadModels(this.config.modelsPath)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to load models: ${error.message}`)\n\t\t}\n\n\t\tmodels = models.filter((schema) => schema instanceof Model)\n\n\t\tthis.mapper = new Cassandra.mapping.Mapper(this.driver, {\n\t\t\tmodels: buildMapper(models),\n\t\t})\n\n\t\tfor (let model of models) {\n\t\t\tthis.models.set(\n\t\t\t\tmodel.name,\n\t\t\t\tmodel as Model<InferDocument<typeof model.schema>>,\n\t\t\t)\n\n\t\t\tif (options?.sync === true) {\n\t\t\t\tawait model._sync()\n\t\t\t}\n\t\t}\n\n\t\tglobalThis.__scylla_client = this\n\n\t\tconsole.log(\"Connecting to ScyllaDB\")\n\t\tawait this.connectWithRetry()\n\t\tconsole.log(\"ScyllaDB Connected\")\n\t}\n\n\tprivate async connectWithRetry(): Promise<void> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\tawait this.driver.connect()\n\t\t\t\treturn\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Connection attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t)\n\n\t\t\t\tif (attempt < this.config.maxRetries!) {\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Failed to connect to ScyllaDB after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate delay(ms: number): Promise<void> {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms))\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.driver.shutdown()\n\t\t\tconsole.log(\"ScyllaDB connection closed\")\n\n\t\t\tdelete globalThis.__scylla_client\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error shutting down ScyllaDB connection:\", error)\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync executeWithRetry<T>(\n\t\toperation: () => Promise<T>,\n\t\toperationName: string = \"operation\",\n\t): Promise<T> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn await operation()\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\n\t\t\t\t// check if error is retryable\n\t\t\t\tif (\n\t\t\t\t\tthis.isRetryableError(error) &&\n\t\t\t\t\tattempt < this.config.maxRetries!\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Operation ${operationName} attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t\t)\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t// if not retryable or last attempt, throw\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Operation ${operationName} failed after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate isRetryableError(error: any): boolean {\n\t\t// retry on network errors, timeouts, and certain ScyllaDB errors\n\t\tconst retryableMessages = [\n\t\t\t\"timeout\",\n\t\t\t\"connection\",\n\t\t\t\"network\",\n\t\t\t\"unavailable\",\n\t\t\t\"overloaded\",\n\t\t\t\"no hosts available\",\n\t\t]\n\n\t\tconst errorMessage = error.message?.toLowerCase() || \"\"\n\n\t\treturn retryableMessages.some((msg) => errorMessage.includes(msg))\n\t}\n}\n\nexport default Client\n"],"mappings":";;;;;;AAiBA,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,EAAE,uBAAuB,0BAA0B,oBACxD,QAAQ;AAET,IAAa,SAAb,MAAoB;CACnB,YAAY,SAAuB,EAAE,EAAE;AACtC,MAAI,WAAW,gBACd,OAAM,IAAI,MACT,sDACA;AAGF,OAAK,SAAS;GACb,YAAY,KAAK,QAAQ,QAAQ,KAAK,EAAE,KAAK;GAC7C,eACE,OAAO,iBAAiB,wBACtB,sBAAsB,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AAI,eAAe,KAAK,OAAO,WAAW,OAAO;AACzD,UAAM,KAAK,MAAM,KAAK,OAAO,WAAY;;;AAK5C,QAAM,IAAI,MACT,uCAAuC,KAAK,OAAO,WAAW,aAAa,WAAW,UACtF;;CAGF,MAAc,IAA2B;AACxC,SAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;;CAGzD,MAAM,WAA0B;AAC/B,MAAI;AACH,SAAM,KAAK,OAAO,UAAU;AAC5B,WAAQ,IAAI,6BAA6B;AAEzC,UAAO,WAAW;WACV,OAAO;AACf,WAAQ,MAAM,4CAA4C,MAAM;AAChE,SAAM;;;CAIR,MAAM,iBACL,WACA,gBAAwB,aACX;EACb,IAAI,YAA0B;AAE9B,OAAK,IAAI,UAAU,GAAG,WAAW,KAAK,OAAO,YAAa,UACzD,KAAI;AACH,UAAO,MAAM,WAAW;WAChB,OAAO;AACf,eAAY;AAGZ,OACC,KAAK,iBAAiB,MAAM,IAC5B,UAAU,KAAK,OAAO,YACrB;AACD,YAAQ,KACP,aAAa,cAAc,WAAW,QAAQ,WAAW,MAAM,UAC/D;AACD,YAAQ,IAAI,eAAe,KAAK,OAAO,WAAW,OAAO;AAEzD,UAAM,KAAK,MAAM,KAAK,OAAO,WAAY;AACzC;;AAID,SAAM;;AAIR,QAAM,IAAI,MACT,aAAa,cAAc,gBAAgB,KAAK,OAAO,WAAW,aAAa,WAAW,UAC1F;;CAGF,iBAAyB,OAAqB;EAE7C,MAAM,oBAAoB;GACzB;GACA;GACA;GACA;GACA;GACA;GACA;EAED,MAAM,eAAe,MAAM,SAAS,aAAa,IAAI;AAErD,SAAO,kBAAkB,MAAM,QAAQ,aAAa,SAAS,IAAI,CAAC"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/cql_gen/create_table.d.ts
4
4
  declare function export_default(model: Model): string;
5
5
  //#endregion
6
6
  export { export_default as default };
7
- //# sourceMappingURL=create_table.d.mts.map
7
+ //# sourceMappingURL=create_table.d.ts.map
@@ -35,4 +35,4 @@ function create_table_default(model) {
35
35
  //#endregion
36
36
  export { create_table_default as default };
37
37
 
38
- //# sourceMappingURL=create_table.mjs.map
38
+ //# sourceMappingURL=create_table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_table.js","names":[],"sources":["../../src/cql_gen/create_table.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default function (model: Model): string {\n\tconst desc = model.schema\n\tconst tableName = desc.table_name\n\tconst keyspace = model.client.config.keyspace\n\tconst fields = desc.fields\n\tconst key = desc.keys\n\tconst clusteringOrder = desc.clustering_order\n\n\tlet columnsDef = \"\"\n\n\tfor (const fieldName in fields) {\n\t\tconst field = fields[fieldName]\n\t\tconst typeStr = typeof field === \"string\" ? field : (field as any)?.type\n\n\t\tif (!typeStr) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid field type for \"${fieldName}\" in model \"${tableName}\"`,\n\t\t\t)\n\t\t}\n\n\t\tcolumnsDef += `\"${fieldName}\" ${typeStr.toUpperCase()}, `\n\t}\n\n\tlet pkDef = \"\"\n\n\tif (typeof key === \"string\") {\n\t\tpkDef = `\"${key}\"`\n\t} else if (Array.isArray(key) && key.length > 0) {\n\t\tconst first = key[0]\n\n\t\tif (Array.isArray(first)) {\n\t\t\tpkDef = `(${first.map((k) => `\"${k}\"`).join(\", \")})`\n\t\t} else {\n\t\t\tpkDef = `\"${first}\"`\n\t\t}\n\n\t\tfor (let i = 1; i < key.length; i++) {\n\t\t\tpkDef += `, \"${key[i]}\"`\n\t\t}\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Missing or invalid primary key in model \"${tableName}\"`,\n\t\t)\n\t}\n\n\tlet clusterClause = \"\"\n\n\tif (clusteringOrder) {\n\t\tlet orderDef = \"\"\n\n\t\tfor (const col in clusteringOrder) {\n\t\t\tif (orderDef !== \"\") {\n\t\t\t\torderDef += \", \"\n\t\t\t}\n\n\t\t\torderDef += `\"${col}\" ${(clusteringOrder[col] as string).toUpperCase()}`\n\t\t}\n\t\tif (orderDef !== \"\") {\n\t\t\tclusterClause = ` WITH CLUSTERING ORDER BY (${orderDef})`\n\t\t}\n\t}\n\n\treturn `CREATE TABLE IF NOT EXISTS ${keyspace}.${tableName} (${columnsDef}PRIMARY KEY (${pkDef}))${clusterClause}`\n}\n"],"mappings":";AAEA,SAAA,qBAAyB,OAAsB;CAC9C,MAAM,OAAO,MAAM;CACnB,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,MAAM,OAAO,OAAO;CACrC,MAAM,SAAS,KAAK;CACpB,MAAM,MAAM,KAAK;CACjB,MAAM,kBAAkB,KAAK;CAE7B,IAAI,aAAa;AAEjB,MAAK,MAAM,aAAa,QAAQ;EAC/B,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,OAAO,UAAU,WAAW,QAAS,OAAe;AAEpE,MAAI,CAAC,QACJ,OAAM,IAAI,MACT,2BAA2B,UAAU,cAAc,UAAU,GAC7D;AAGF,gBAAc,IAAI,UAAU,IAAI,QAAQ,aAAa,CAAC;;CAGvD,IAAI,QAAQ;AAEZ,KAAI,OAAO,QAAQ,SAClB,SAAQ,IAAI,IAAI;UACN,MAAM,QAAQ,IAAI,IAAI,IAAI,SAAS,GAAG;EAChD,MAAM,QAAQ,IAAI;AAElB,MAAI,MAAM,QAAQ,MAAM,CACvB,SAAQ,IAAI,MAAM,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC;MAElD,SAAQ,IAAI,MAAM;AAGnB,OAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC/B,UAAS,MAAM,IAAI,GAAG;OAGvB,OAAM,IAAI,MACT,4CAA4C,UAAU,GACtD;CAGF,IAAI,gBAAgB;AAEpB,KAAI,iBAAiB;EACpB,IAAI,WAAW;AAEf,OAAK,MAAM,OAAO,iBAAiB;AAClC,OAAI,aAAa,GAChB,aAAY;AAGb,eAAY,IAAI,IAAI,IAAK,gBAAgB,KAAgB,aAAa;;AAEvE,MAAI,aAAa,GAChB,iBAAgB,8BAA8B,SAAS;;AAIzD,QAAO,8BAA8B,SAAS,GAAG,UAAU,IAAI,WAAW,eAAe,MAAM,IAAI"}
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Schema } from "./schema/index.js";
2
+ import { Model } from "./model/index.js";
3
+ import { Result } from "./result/index.js";
4
+ import { ColumnTypes } from "./types.js";
5
+ import { Client } from "./client.js";
6
+ export { Client, Client as default, ColumnTypes, Model, Result, Schema };
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { Result } from "./result/index.js";
2
+ import { Model } from "./model/index.js";
3
+ import { Client } from "./client.js";
4
+ import { Schema } from "./schema/index.js";
5
+ import { ColumnTypes } from "./types.js";
6
+ //#region src/index.ts
7
+ var src_default = Client;
8
+ //#endregion
9
+ export { Client, ColumnTypes, Model, Result, Schema, src_default as default };
10
+
11
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import Client from \"./client\"\nimport Model from \"./model\"\nimport Schema from \"./schema\"\nimport Result from \"./result\"\nimport { ColumnTypes } from \"./types\"\n\nexport default Client\nexport { Client, Model, Schema, Result, ColumnTypes }\n"],"mappings":";;;;;;AAMA,IAAA,cAAe"}
@@ -1,8 +1,8 @@
1
- import { Schema } from "../schema/index.mjs";
2
- import export_default from "../operations/tableExists.mjs";
3
- import syncOP from "../operations/sync.mjs";
4
- import { DocumentResult, Query, QueryOptions } from "../types.mjs";
5
- import { Client } from "../client.mjs";
1
+ import { Schema } from "../schema/index.js";
2
+ import export_default from "../operations/tableExists.js";
3
+ import syncOP from "../operations/sync.js";
4
+ import { DocumentResult, Query, QueryOptions } from "../types.js";
5
+ import { Client } from "../client.js";
6
6
  import { mapping } from "cassandra-driver/lib/mapping/index.js";
7
7
 
8
8
  //#region src/model/index.d.ts
@@ -34,4 +34,4 @@ declare class Model<TDoc = any> {
34
34
  }
35
35
  //#endregion
36
36
  export { Model, Model as default };
37
- //# sourceMappingURL=index.d.mts.map
37
+ //# sourceMappingURL=index.d.ts.map
@@ -1,12 +1,12 @@
1
- import { Result } from "../result/index.mjs";
2
- import fillDefaults from "../utils/fillDefaults.mjs";
3
- import findOne_default from "../operations/findOne.mjs";
4
- import findOP from "../operations/find.mjs";
5
- import update_default from "../operations/update.mjs";
6
- import delete_default from "../operations/delete.mjs";
7
- import countAll_default from "../operations/countAll.mjs";
8
- import tableExists_default from "../operations/tableExists.mjs";
9
- import syncOP from "../operations/sync.mjs";
1
+ import { Result } from "../result/index.js";
2
+ import fillDefaults from "../utils/fillDefaults.js";
3
+ import findOne_default from "../operations/findOne.js";
4
+ import findOP from "../operations/find.js";
5
+ import update_default from "../operations/update.js";
6
+ import delete_default from "../operations/delete.js";
7
+ import countAll_default from "../operations/countAll.js";
8
+ import tableExists_default from "../operations/tableExists.js";
9
+ import syncOP from "../operations/sync.js";
10
10
  //#region src/model/index.ts
11
11
  var Model = class {
12
12
  name;
@@ -42,4 +42,4 @@ var Model = class {
42
42
  //#endregion
43
43
  export { Model, Model as default };
44
44
 
45
- //# sourceMappingURL=index.mjs.map
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["findOneOP","updateOP","deleteOP","countAllOP","tableExistsOP"],"sources":["../../src/model/index.ts"],"sourcesContent":["import Client from \"..\"\nimport { Result } from \"../result\"\n\nimport fillDefaults from \"../utils/fillDefaults\"\n\nimport { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { DocumentResult, Query, QueryOptions } from \"../types\"\nimport type { Schema } from \"../schema\"\n\nimport findOneOP from \"../operations/findOne\"\nimport findOP from \"../operations/find\"\nimport updateOP from \"../operations/update\"\nimport deleteOP from \"../operations/delete\"\nimport countAllOP from \"../operations/countAll\"\n\nimport tableExistsOP from \"../operations/tableExists\"\nimport syncOP from \"../operations/sync\"\n\nexport class Model<TDoc = any> {\n\tname: string\n\tschema: Schema<any>\n\n\tget client(): Client {\n\t\treturn globalThis.__scylla_client\n\t}\n\n\tget mapper(): mapping.ModelMapper {\n\t\tif (!globalThis.__scylla_client?.mapper) {\n\t\t\tthrow new Error(\"No mapper available\")\n\t\t}\n\n\t\treturn globalThis.__scylla_client.mapper.forModel(this.name)\n\t}\n\n\tconstructor(name: string, schema: Schema<any>) {\n\t\tthis.name = name\n\t\tthis.schema = schema\n\n\t\tif (!Array.isArray(this.schema.keys)) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"keys\" array`)\n\t\t}\n\t\tif (!this.schema.table_name) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"table_name\"`)\n\t\t}\n\t\tif (!this.schema.fields || typeof this.schema.fields !== \"object\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[${this.name}] model has missing or invalid \"fields\"`,\n\t\t\t)\n\t\t}\n\t}\n\n\tcreate = (data: Partial<TDoc>) => this._wrap(data)\n\n\tfind: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc[]>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>[]>\n\t} = findOP.bind(this)\n\n\tfindOne: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>>\n\t} = findOneOP.bind(this)\n\n\tupdate: (query: Query<TDoc>) => Promise<DocumentResult<TDoc>> =\n\t\tupdateOP.bind(this)\n\n\tdelete: (query: Query<TDoc>) => Promise<mapping.Result> =\n\t\tdeleteOP.bind(this)\n\n\tcountAll: () => Promise<number> = countAllOP.bind(this)\n\n\t_sync: typeof syncOP = syncOP.bind(this)\n\t_tableExists: typeof tableExistsOP = tableExistsOP.bind(this)\n\n\t_wrap(row: any): DocumentResult<TDoc> | null {\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\n\t\trow = fillDefaults(this.schema, row)\n\n\t\treturn new Result<TDoc>(row, this) as DocumentResult<TDoc>\n\t}\n}\n\nexport default Model\n"],"mappings":";;;;;;;;;;AAkBA,IAAa,QAAb,MAA+B;CAC9B;CACA;CAEA,IAAI,SAAiB;AACpB,SAAO,WAAW;;CAGnB,IAAI,SAA8B;AACjC,MAAI,CAAC,WAAW,iBAAiB,OAChC,OAAM,IAAI,MAAM,sBAAsB;AAGvC,SAAO,WAAW,gBAAgB,OAAO,SAAS,KAAK,KAAK;;CAG7D,YAAY,MAAc,QAAqB;AAC9C,OAAK,OAAO;AACZ,OAAK,SAAS;AAEd,MAAI,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,CACnC,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,WAChB,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,UAAU,OAAO,KAAK,OAAO,WAAW,SACxD,OAAM,IAAI,MACT,IAAI,KAAK,KAAK,yCACd;;CAIH,UAAU,SAAwB,KAAK,MAAM,KAAK;CAElD,OASI,OAAO,KAAK,KAAK;CAErB,UASIA,gBAAU,KAAK,KAAK;CAExB,SACCC,eAAS,KAAK,KAAK;CAEpB,SACCC,eAAS,KAAK,KAAK;CAEpB,WAAkCC,iBAAW,KAAK,KAAK;CAEvD,QAAuB,OAAO,KAAK,KAAK;CACxC,eAAqCC,oBAAc,KAAK,KAAK;CAE7D,MAAM,KAAuC;AAC5C,MAAI,CAAC,IACJ,QAAO;AAGR,QAAM,aAAa,KAAK,QAAQ,IAAI;AAEpC,SAAO,IAAI,OAAa,KAAK,KAAK"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/operations/countAll.d.ts
4
4
  declare function export_default(this: Model, timeoutMs?: number): Promise<any>;
5
5
  //#endregion
6
6
  export { export_default as default };
7
- //# sourceMappingURL=countAll.d.mts.map
7
+ //# sourceMappingURL=countAll.d.ts.map
@@ -13,4 +13,4 @@ async function countAll_default(timeoutMs = 6e4) {
13
13
  //#endregion
14
14
  export { countAll_default as default };
15
15
 
16
- //# sourceMappingURL=countAll.mjs.map
16
+ //# sourceMappingURL=countAll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countAll.js","names":[],"sources":["../../src/operations/countAll.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model, timeoutMs: number = 60000) {\n\tconst cql = `SELECT COUNT(1) FROM ${this.client.config.keyspace}.${this.schema.table_name}`\n\n\tconst queryOptions = {\n\t\tprepare: true,\n\t\treadTimeout: timeoutMs,\n\t}\n\n\tconst operation = async () => {\n\t\tconst result = await this.client.driver.execute(cql, [], queryOptions)\n\n\t\treturn result.rows[0].count.toNumber()\n\t}\n\n\treturn this.client.executeWithRetry(operation, `countAll on ${this.name}`)\n}\n"],"mappings":";AAEA,eAAA,iBAA4C,YAAoB,KAAO;CACtE,MAAM,MAAM,wBAAwB,KAAK,OAAO,OAAO,SAAS,GAAG,KAAK,OAAO;CAE/E,MAAM,eAAe;EACpB,SAAS;EACT,aAAa;EACb;CAED,MAAM,YAAY,YAAY;AAG7B,UAAO,MAFc,KAAK,OAAO,OAAO,QAAQ,KAAK,EAAE,EAAE,aAAa,EAExD,KAAK,GAAG,MAAM,UAAU;;AAGvC,QAAO,KAAK,OAAO,iBAAiB,WAAW,eAAe,KAAK,OAAO"}
@@ -1,8 +1,8 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
  import * as _$cassandra_driver0 from "cassandra-driver";
3
3
 
4
4
  //#region src/operations/delete.d.ts
5
5
  declare function export_default(this: Model, query: any): Promise<_$cassandra_driver0.mapping.Result<any>>;
6
6
  //#endregion
7
7
  export { export_default as default };
8
- //# sourceMappingURL=delete.d.mts.map
8
+ //# sourceMappingURL=delete.d.ts.map
@@ -8,4 +8,4 @@ async function delete_default(query) {
8
8
  //#endregion
9
9
  export { delete_default as default };
10
10
 
11
- //# sourceMappingURL=delete.mjs.map
11
+ //# sourceMappingURL=delete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.js","names":[],"sources":["../../src/operations/delete.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model, query: any) {\n\tconst operation = async () => {\n\t\treturn await this.mapper.remove(query)\n\t}\n\n\treturn this.client.executeWithRetry(operation, `delete on ${this.name}`)\n}\n"],"mappings":";AAEA,eAAA,eAA4C,OAAY;CACvD,MAAM,YAAY,YAAY;AAC7B,SAAO,MAAM,KAAK,OAAO,OAAO,MAAM;;AAGvC,QAAO,KAAK,OAAO,iBAAiB,WAAW,aAAa,KAAK,OAAO"}
@@ -1,8 +1,8 @@
1
- import { Model } from "../model/index.mjs";
2
- import { Query, QueryOptions } from "../types.mjs";
1
+ import { Model } from "../model/index.js";
2
+ import { Query, QueryOptions } from "../types.js";
3
3
 
4
4
  //#region src/operations/find.d.ts
5
5
  declare function findOP<TDoc>(this: Model<TDoc>, query?: Query<TDoc>, options?: QueryOptions): Promise<any[]>;
6
6
  //#endregion
7
7
  export { findOP as default };
8
- //# sourceMappingURL=find.d.mts.map
8
+ //# sourceMappingURL=find.d.ts.map
@@ -1,4 +1,4 @@
1
- import queryParser from "../utils/queryParser.mjs";
1
+ import queryParser from "../utils/queryParser.js";
2
2
  //#region src/operations/find.ts
3
3
  async function findOP(query = {}, options) {
4
4
  const { $limit, $orderby, ...rest } = query;
@@ -19,4 +19,4 @@ async function findOP(query = {}, options) {
19
19
  //#endregion
20
20
  export { findOP as default };
21
21
 
22
- //# sourceMappingURL=find.mjs.map
22
+ //# sourceMappingURL=find.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.js","names":[],"sources":["../../src/operations/find.ts"],"sourcesContent":["import type Model from \"../model\"\nimport type { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { Query, QueryOptions } from \"../types\"\nimport queryParser from \"../utils/queryParser\"\n\nexport default async function findOP<TDoc>(\n\tthis: Model<TDoc>,\n\tquery: Query<TDoc> = {},\n\toptions?: QueryOptions,\n) {\n\tconst { $limit, $orderby, ...rest } = query\n\n\tlet parsedQuery = queryParser(this, rest)\n\n\tconst docInfo: mapping.FindDocInfo = {}\n\n\tif ($limit !== undefined) {\n\t\tif (typeof $limit !== \"number\" || $limit <= 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`{$limit} operator must be a number greater than 0`,\n\t\t\t)\n\t\t}\n\t\tdocInfo.limit = $limit\n\t}\n\n\tif ($orderby !== undefined) {\n\t\tdocInfo.orderBy = $orderby as Record<string, \"asc\" | \"desc\">\n\t}\n\n\tconst operation = async () => {\n\t\tconst result = await this.mapper.find(parsedQuery, docInfo)\n\t\tconst rows = result.toArray()\n\n\t\tif (options?.raw === true) {\n\t\t\treturn rows\n\t\t}\n\n\t\treturn rows.map((row) => this._wrap(row))\n\t}\n\n\treturn this.client.executeWithRetry(operation, `find on ${this.name}`)\n}\n"],"mappings":";;AAKA,eAA8B,OAE7B,QAAqB,EAAE,EACvB,SACC;CACD,MAAM,EAAE,QAAQ,UAAU,GAAG,SAAS;CAEtC,IAAI,cAAc,YAAY,MAAM,KAAK;CAEzC,MAAM,UAA+B,EAAE;AAEvC,KAAI,WAAW,KAAA,GAAW;AACzB,MAAI,OAAO,WAAW,YAAY,UAAU,EAC3C,OAAM,IAAI,UACT,oDACA;AAEF,UAAQ,QAAQ;;AAGjB,KAAI,aAAa,KAAA,EAChB,SAAQ,UAAU;CAGnB,MAAM,YAAY,YAAY;EAE7B,MAAM,QAAO,MADQ,KAAK,OAAO,KAAK,aAAa,QAAQ,EACvC,SAAS;AAE7B,MAAI,SAAS,QAAQ,KACpB,QAAO;AAGR,SAAO,KAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;;AAG1C,QAAO,KAAK,OAAO,iBAAiB,WAAW,WAAW,KAAK,OAAO"}
@@ -1,8 +1,8 @@
1
- import { Model } from "../model/index.mjs";
2
- import { QueryOptions } from "../types.mjs";
1
+ import { Model } from "../model/index.js";
2
+ import { QueryOptions } from "../types.js";
3
3
 
4
4
  //#region src/operations/findOne.d.ts
5
5
  declare function export_default(this: Model, query: any, options?: QueryOptions): Promise<any>;
6
6
  //#endregion
7
7
  export { export_default as default };
8
- //# sourceMappingURL=findOne.d.mts.map
8
+ //# sourceMappingURL=findOne.d.ts.map
@@ -1,4 +1,4 @@
1
- import queryParser from "../utils/queryParser.mjs";
1
+ import queryParser from "../utils/queryParser.js";
2
2
  //#region src/operations/findOne.ts
3
3
  function findOne_default(query, options) {
4
4
  query = queryParser(this, query);
@@ -14,4 +14,4 @@ function findOne_default(query, options) {
14
14
  //#endregion
15
15
  export { findOne_default as default };
16
16
 
17
- //# sourceMappingURL=findOne.mjs.map
17
+ //# sourceMappingURL=findOne.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOne.js","names":[],"sources":["../../src/operations/findOne.ts"],"sourcesContent":["import type { QueryOptions } from \"../types\"\nimport type Model from \"../model\"\nimport queryParser from \"../utils/queryParser\"\n\nexport default function (this: Model, query: any, options?: QueryOptions) {\n\tquery = queryParser(this, query)\n\n\tconst operation = async () => {\n\t\tlet result = await this.mapper.get(query)\n\n\t\tif (!result) {\n\t\t\treturn null\n\t\t}\n\n\t\tresult = this._wrap(result)\n\n\t\tif (options?.raw === true) {\n\t\t\treturn result.toRaw()\n\t\t}\n\n\t\treturn result\n\t}\n\n\treturn this.client.executeWithRetry(operation, `findOne on ${this.name}`)\n}\n"],"mappings":";;AAIA,SAAA,gBAAsC,OAAY,SAAwB;AACzE,SAAQ,YAAY,MAAM,MAAM;CAEhC,MAAM,YAAY,YAAY;EAC7B,IAAI,SAAS,MAAM,KAAK,OAAO,IAAI,MAAM;AAEzC,MAAI,CAAC,OACJ,QAAO;AAGR,WAAS,KAAK,MAAM,OAAO;AAE3B,MAAI,SAAS,QAAQ,KACpB,QAAO,OAAO,OAAO;AAGtB,SAAO;;AAGR,QAAO,KAAK,OAAO,iBAAiB,WAAW,cAAc,KAAK,OAAO"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/operations/sync.d.ts
4
4
  declare function syncOP(this: Model): Promise<void>;
5
5
  //#endregion
6
6
  export { syncOP as default };
7
- //# sourceMappingURL=sync.d.mts.map
7
+ //# sourceMappingURL=sync.d.ts.map
@@ -1,4 +1,4 @@
1
- import create_table_default from "../cql_gen/create_table.mjs";
1
+ import create_table_default from "../cql_gen/create_table.js";
2
2
  //#region src/operations/sync.ts
3
3
  async function syncOP() {
4
4
  if (await this._tableExists()) return;
@@ -13,4 +13,4 @@ async function syncOP() {
13
13
  //#endregion
14
14
  export { syncOP as default };
15
15
 
16
- //# sourceMappingURL=sync.mjs.map
16
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","names":["generateCreateTableCQL"],"sources":["../../src/operations/sync.ts"],"sourcesContent":["import type Model from \"../model\"\nimport generateCreateTableCQL from \"../cql_gen/create_table\"\n\nexport default async function syncOP(this: Model) {\n\tconst tableExists = await this._tableExists()\n\n\tif (tableExists) {\n\t\treturn\n\t}\n\n\ttry {\n\t\tawait this.client.driver.execute(generateCreateTableCQL(this))\n\n\t\tconsole.log(`Table \"${this.schema.table_name}\" created successfully`)\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`Failed to create table \"${this.schema.table_name}\":`,\n\t\t\terror,\n\t\t)\n\t\tthrow error\n\t}\n}\n"],"mappings":";;AAGA,eAA8B,SAAoB;AAGjD,KAAI,MAFsB,KAAK,cAAc,CAG5C;AAGD,KAAI;AACH,QAAM,KAAK,OAAO,OAAO,QAAQA,qBAAuB,KAAK,CAAC;AAE9D,UAAQ,IAAI,UAAU,KAAK,OAAO,WAAW,wBAAwB;UAC7D,OAAO;AACf,UAAQ,MACP,2BAA2B,KAAK,OAAO,WAAW,KAClD,MACA;AACD,QAAM"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/operations/tableExists.d.ts
4
4
  declare function export_default(this: Model): Promise<boolean>;
5
5
  //#endregion
6
6
  export { export_default as default };
7
- //# sourceMappingURL=tableExists.d.mts.map
7
+ //# sourceMappingURL=tableExists.d.ts.map
@@ -16,4 +16,4 @@ async function tableExists_default() {
16
16
  //#endregion
17
17
  export { tableExists_default as default };
18
18
 
19
- //# sourceMappingURL=tableExists.mjs.map
19
+ //# sourceMappingURL=tableExists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableExists.js","names":[],"sources":["../../src/operations/tableExists.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model) {\n\tconst cql = `\n\t\t\tSELECT table_name\n\t\t\tFROM system_schema.tables\n\t\t\tWHERE keyspace_name = ?\n\t\t\tAND table_name = ?\n\t\t`\n\n\ttry {\n\t\tconst result = await this.client.driver.execute(\n\t\t\tcql,\n\t\t\t[this.client.config.keyspace, this.schema.table_name],\n\t\t\t{\n\t\t\t\tprepare: true,\n\t\t\t},\n\t\t)\n\n\t\treturn result.rows.length > 0\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`Failed to check if table \"${this.schema.table_name}\" exists:`,\n\t\t\terror,\n\t\t)\n\n\t\treturn false\n\t}\n}\n"],"mappings":";AAEA,eAAA,sBAA4C;CAC3C,MAAM,MAAM;;;;;;AAOZ,KAAI;AASH,UAAO,MARc,KAAK,OAAO,OAAO,QACvC,KACA,CAAC,KAAK,OAAO,OAAO,UAAU,KAAK,OAAO,WAAW,EACrD,EACC,SAAS,MACT,CACD,EAEa,KAAK,SAAS;UACpB,OAAO;AACf,UAAQ,MACP,6BAA6B,KAAK,OAAO,WAAW,YACpD,MACA;AAED,SAAO"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/operations/update.d.ts
4
4
  declare function export_default(this: Model, query: any): Promise<any>;
5
5
  //#endregion
6
6
  export { export_default as default };
7
- //# sourceMappingURL=update.d.mts.map
7
+ //# sourceMappingURL=update.d.ts.map
@@ -1,5 +1,5 @@
1
- import typeChecker from "../utils/typeChecker.mjs";
2
- import fillDefaults from "../utils/fillDefaults.mjs";
1
+ import typeChecker from "../utils/typeChecker.js";
2
+ import fillDefaults from "../utils/fillDefaults.js";
3
3
  //#region src/operations/update.ts
4
4
  async function update_default(query) {
5
5
  query = fillDefaults(this.schema, query);
@@ -15,4 +15,4 @@ async function update_default(query) {
15
15
  //#endregion
16
16
  export { update_default as default };
17
17
 
18
- //# sourceMappingURL=update.mjs.map
18
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","names":[],"sources":["../../src/operations/update.ts"],"sourcesContent":["import type Model from \"../model\"\nimport fillDefaults from \"../utils/fillDefaults\"\nimport typeChecker from \"../utils/typeChecker\"\n\nexport default async function (this: Model, query: any) {\n\tquery = fillDefaults(this.schema, query)\n\n\ttypeChecker(this, query)\n\n\tif (typeof query.__v !== \"undefined\") {\n\t\tif (Number.isNaN(query.__v)) {\n\t\t\tquery.__v = 0\n\t\t} else {\n\t\t\tquery.__v = query.__v + 1\n\t\t}\n\t}\n\n\tconst operation = async () => {\n\t\tawait this.mapper.update(query)\n\t\treturn this._wrap(query)\n\t}\n\n\treturn this.client.executeWithRetry(operation, `update on ${this.name}`)\n}\n"],"mappings":";;;AAIA,eAAA,eAA4C,OAAY;AACvD,SAAQ,aAAa,KAAK,QAAQ,MAAM;AAExC,aAAY,MAAM,MAAM;AAExB,KAAI,OAAO,MAAM,QAAQ,YACxB,KAAI,OAAO,MAAM,MAAM,IAAI,CAC1B,OAAM,MAAM;KAEZ,OAAM,MAAM,MAAM,MAAM;CAI1B,MAAM,YAAY,YAAY;AAC7B,QAAM,KAAK,OAAO,OAAO,MAAM;AAC/B,SAAO,KAAK,MAAM,MAAM;;AAGzB,QAAO,KAAK,OAAO,iBAAiB,WAAW,aAAa,KAAK,OAAO"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ragestudio/scylla-odm",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "An ODM for ScyllaDB",
5
5
  "license": "MIT",
6
6
  "author": "RageStudio",
7
7
  "type": "module",
8
- "types": "./index.d.mts",
9
- "module": "./index.mjs",
8
+ "types": "./index.d.ts",
9
+ "module": "./index.js",
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
@@ -1,5 +1,5 @@
1
- import { Model } from "../model/index.mjs";
2
- import { DocumentResult } from "../types.mjs";
1
+ import { Model } from "../model/index.js";
2
+ import { DocumentResult } from "../types.js";
3
3
  import * as _$cassandra_driver0 from "cassandra-driver";
4
4
 
5
5
  //#region src/result/index.d.ts
@@ -14,4 +14,4 @@ declare class Result<TDoc = any> {
14
14
  }
15
15
  //#endregion
16
16
  export { Result, Result as default };
17
- //# sourceMappingURL=index.d.mts.map
17
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import typeChecker from "../utils/typeChecker.mjs";
1
+ import typeChecker from "../utils/typeChecker.js";
2
2
  //#region src/result/index.ts
3
3
  var Result = class {
4
4
  constructor(data, model) {
@@ -63,4 +63,4 @@ var Result = class {
63
63
  //#endregion
64
64
  export { Result, Result as default };
65
65
 
66
- //# sourceMappingURL=index.mjs.map
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/result/index.ts"],"sourcesContent":["import type { Model } from \"../model\"\nimport typeChecker from \"../utils/typeChecker\"\n\nexport class Result<TDoc = any> {\n\tconstructor(data: TDoc, model: Model<TDoc>) {\n\t\tif (data == null) {\n\t\t\tthrow new Error(\"Cannot create Result with null or undefined data\")\n\t\t}\n\n\t\tif (typeof data !== \"object\" || Array.isArray(data)) {\n\t\t\tthrow new Error(\"Result data must be an object\")\n\t\t}\n\n\t\tObject.assign(this, data)\n\n\t\tObject.defineProperty(this, \"_model\", {\n\t\t\tvalue: model,\n\t\t\tenumerable: false,\n\t\t\twritable: false,\n\t\t\tconfigurable: false,\n\t\t})\n\t}\n\n\t_model: Model<TDoc>\n\n\tasync save() {\n\t\ttry {\n\t\t\tconst data = this.toRaw()\n\n\t\t\ttypeChecker(this._model, data)\n\n\t\t\treturn await this._model.update(data as any)\n\t\t} catch (error: any) {\n\t\t\tthrow new Error(`Failed to save result: ${error.message}`)\n\t\t}\n\t}\n\n\tasync delete() {\n\t\ttry {\n\t\t\treturn await this._model.delete(this.toRaw() as any)\n\t\t} catch (error: any) {\n\t\t\tthrow new Error(`Failed to delete result: ${error.message}`)\n\t\t}\n\t}\n\n\ttoRaw(): TDoc {\n\t\tconst raw: any = {}\n\n\t\tfor (const key in this) {\n\t\t\tif (key === \"_model\") continue\n\n\t\t\tif (this.propertyIsEnumerable(key)) {\n\t\t\t\tconst value = (this as any)[key]\n\n\t\t\t\ttry {\n\t\t\t\t\tJSON.stringify(value)\n\t\t\t\t\traw[key] = value\n\t\t\t\t} catch (error) {\n\t\t\t\t\traw[key] = String(value)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn raw as TDoc\n\t}\n\n\tisValid(): boolean {\n\t\ttry {\n\t\t\ttypeChecker(this._model, this.toRaw())\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\tgetChangedFields(original: Partial<TDoc>): (keyof TDoc)[] {\n\t\tconst current = this.toRaw() as Record<string, any>\n\t\tconst changed: (keyof TDoc)[] = []\n\n\t\tfor (const key in current) {\n\t\t\tif (!(key in original) || current[key] !== (original as any)[key]) {\n\t\t\t\tchanged.push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AQ,SAAU,SAAiB,KAC5D,SAAQ,KAAK,IAAkB;AAIjC,SAAO"}
@@ -1,4 +1,4 @@
1
- import { TableKeys } from "../types.mjs";
1
+ import { TableKeys } from "../types.js";
2
2
 
3
3
  //#region src/schema/index.d.ts
4
4
  declare class Schema<T> {
@@ -10,4 +10,4 @@ declare class Schema<T> {
10
10
  }
11
11
  //#endregion
12
12
  export { Schema, Schema as default };
13
- //# sourceMappingURL=index.d.mts.map
13
+ //# sourceMappingURL=index.d.ts.map
@@ -13,4 +13,4 @@ var Schema = class {
13
13
  //#endregion
14
14
  export { Schema, Schema as default };
15
15
 
16
- //# sourceMappingURL=index.mjs.map
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/schema/index.ts"],"sourcesContent":["import { TableKeys } from \"../types\"\n\nexport class Schema<T> {\n\tpublic readonly table_name: string\n\tpublic readonly clustering_order: any\n\tpublic readonly keys: TableKeys\n\tpublic readonly fields: T\n\n\tconstructor(params: any, fields: T) {\n\t\tthis.table_name = params.table_name\n\t\tthis.keys = params.keys\n\t\tthis.fields = fields\n\t}\n}\n\nexport default Schema\n"],"mappings":";AAEA,IAAa,SAAb,MAAuB;CACtB;CACA;CACA;CACA;CAEA,YAAY,QAAa,QAAW;AACnC,OAAK,aAAa,OAAO;AACzB,OAAK,OAAO,OAAO;AACnB,OAAK,SAAS"}
@@ -1,5 +1,5 @@
1
- import { Schema } from "./schema/index.mjs";
2
- import { Result } from "./result/index.mjs";
1
+ import { Schema } from "./schema/index.js";
2
+ import { Result } from "./result/index.js";
3
3
 
4
4
  //#region src/types.d.ts
5
5
  type ClientConfig = {
@@ -71,4 +71,4 @@ type Query<TDoc> = { [K in keyof TDoc]?: TDoc[K] | QueryOperators<TDoc[K]> } & {
71
71
  };
72
72
  //#endregion
73
73
  export { ClientConfig, Column, ColumnTypes, DocumentResult, InferDocument, InferRawData, OrderBy, Query, QueryOperators, QueryOptions, TableKeys };
74
- //# sourceMappingURL=types.d.mts.map
74
+ //# sourceMappingURL=types.d.ts.map
@@ -31,4 +31,4 @@ let ColumnTypes = /* @__PURE__ */ function(ColumnTypes) {
31
31
  //#endregion
32
32
  export { ColumnTypes };
33
33
 
34
- //# sourceMappingURL=types.mjs.map
34
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import Result from \"./result\"\nimport { Schema } from \"./schema\"\n\nexport type ClientConfig = {\n\tmodelsPath?: string\n\tcontactPoints?: string[]\n\tlocalDataCenter?: string\n\tkeyspace?: string\n\tport?: number\n\tmaxRetries?: number\n\tretryDelay?: number\n\tpooling?: {\n\t\tcoreConnectionsPerHost?: Record<string, number>\n\t\tmaxRequestsPerConnection?: number\n\t}\n}\n\nexport enum ColumnTypes {\n\tAscii = \"ascii\",\n\tBigint = \"bigint\",\n\tBlob = \"blob\",\n\tBoolean = \"boolean\",\n\tCounter = \"counter\",\n\tDate = \"date\",\n\tDecimal = \"decimal\",\n\tDouble = \"double\",\n\tDuration = \"duration\",\n\tFloat = \"float\",\n\tFrozen = \"frozen\",\n\tInet = \"inet\",\n\tInt = \"int\",\n\tList = \"list\",\n\tMap = \"map\",\n\tSet = \"set\",\n\tSmallint = \"smallint\",\n\tText = \"text\",\n\tTime = \"time\",\n\tTimestamp = \"timestamp\",\n\tTimeuuid = \"timeuuid\",\n\tTinyint = \"tinyint\",\n\tTuple = \"tuple\",\n\tUuid = \"uuid\",\n\tVarchar = \"varchar\",\n\tVarint = \"varint\",\n}\n\nexport type QueryOperators<TValue> = {\n\t$eq?: TValue\n\t$ne?: TValue\n\t$in?: TValue[]\n\t$gt?: TValue\n\t$gte?: TValue\n\t$lt?: TValue\n\t$lte?: TValue\n}\n\nexport type TableKeys = (string | TableKeys)[]\n\nexport interface Column<T> {\n\ttype?: ColumnTypes | string\n\trequired?: boolean\n}\n\nexport type InferRawData<T> = {\n\t[K in keyof T as K extends `$${string}` ? never : K]: T[K] extends Column<\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: T[K]\n}\n\nexport type InferDocument<S> =\n\tS extends Schema<infer T> ? InferRawData<T> : never\n\n// export type DocOf<M extends Model<any>> =\n// \tM extends Model<infer S> ? InferDocument<S> : never\n\nexport type DocumentResult<TDoc> = Result<TDoc> & TDoc\n\nexport type QueryOptions = {\n\traw?: boolean\n}\n\nexport type OrderBy<TDoc> = { [K in keyof TDoc]?: \"asc\" | \"desc\" }\n\nexport type Query<TDoc> = {\n\t[K in keyof TDoc]?: TDoc[K] | QueryOperators<TDoc[K]>\n} & {\n\t$and?: Query<TDoc>[]\n\t$limit?: number\n\t$orderby?: OrderBy<TDoc>\n}\n"],"mappings":";AAiBA,IAAY,cAAL,yBAAA,aAAA;AACN,aAAA,WAAA;AACA,aAAA,YAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,aAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,YAAA;AACA,aAAA,cAAA;AACA,aAAA,WAAA;AACA,aAAA,YAAA;AACA,aAAA,UAAA;AACA,aAAA,SAAA;AACA,aAAA,UAAA;AACA,aAAA,SAAA;AACA,aAAA,SAAA;AACA,aAAA,cAAA;AACA,aAAA,UAAA;AACA,aAAA,UAAA;AACA,aAAA,eAAA;AACA,aAAA,cAAA;AACA,aAAA,aAAA;AACA,aAAA,WAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,YAAA;;KACA"}
@@ -2,4 +2,4 @@
2
2
  declare const _default: (map: any) => any;
3
3
  //#endregion
4
4
  export { _default as default };
5
- //# sourceMappingURL=buildMapper.d.mts.map
5
+ //# sourceMappingURL=buildMapper.d.ts.map
@@ -10,4 +10,4 @@ var buildMapper_default = (map) => {
10
10
  //#endregion
11
11
  export { buildMapper_default as default };
12
12
 
13
- //# sourceMappingURL=buildMapper.mjs.map
13
+ //# sourceMappingURL=buildMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildMapper.js","names":[],"sources":["../../src/utils/buildMapper.ts"],"sourcesContent":["export default (map) => {\n\treturn map.reduce((obj, { name, schema }) => {\n\t\treturn {\n\t\t\t...obj,\n\t\t\t[name]: {\n\t\t\t\ttables: [schema.table_name],\n\t\t\t},\n\t\t}\n\t}, {})\n}\n"],"mappings":";AAAA,IAAA,uBAAgB,QAAQ;AACvB,QAAO,IAAI,QAAQ,KAAK,EAAE,MAAM,aAAa;AAC5C,SAAO;GACN,GAAG;IACF,OAAO,EACP,QAAQ,CAAC,OAAO,WAAW,EAC3B;GACD;IACC,EAAE,CAAC"}
@@ -2,4 +2,4 @@
2
2
  declare function fillDefaults(schema: any, data: any): any;
3
3
  //#endregion
4
4
  export { fillDefaults as default };
5
- //# sourceMappingURL=fillDefaults.d.mts.map
5
+ //# sourceMappingURL=fillDefaults.d.ts.map
@@ -15,4 +15,4 @@ function fillDefaults(schema, data) {
15
15
  //#endregion
16
16
  export { fillDefaults as default };
17
17
 
18
- //# sourceMappingURL=fillDefaults.mjs.map
18
+ //# sourceMappingURL=fillDefaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fillDefaults.js","names":[],"sources":["../../src/utils/fillDefaults.ts"],"sourcesContent":["export default function fillDefaults(schema: any, data: any) {\n\tconst defaults = schema.options?.defaults\n\n\tif (!defaults || Object.keys(defaults).length === 0) {\n\t\treturn data\n\t}\n\n\tlet needsDefaults = false\n\n\tfor (const key in defaults) {\n\t\tif (data[key] == null) {\n\t\t\tneedsDefaults = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (!needsDefaults) {\n\t\treturn data\n\t}\n\n\tconst result = Object.assign({}, data)\n\n\tfor (const key in defaults) {\n\t\tif (result[key] == null) {\n\t\t\tresult[key] = defaults[key]\n\t\t}\n\t}\n\n\treturn result\n}\n"],"mappings":";AAAA,SAAwB,aAAa,QAAa,MAAW;CAC5D,MAAM,WAAW,OAAO,SAAS;AAEjC,KAAI,CAAC,YAAY,OAAO,KAAK,SAAS,CAAC,WAAW,EACjD,QAAO;CAGR,IAAI,gBAAgB;AAEpB,MAAK,MAAM,OAAO,SACjB,KAAI,KAAK,QAAQ,MAAM;AACtB,kBAAgB;AAChB;;AAIF,KAAI,CAAC,cACJ,QAAO;CAGR,MAAM,SAAS,OAAO,OAAO,EAAE,EAAE,KAAK;AAEtC,MAAK,MAAM,OAAO,SACjB,KAAI,OAAO,QAAQ,KAClB,QAAO,OAAO,SAAS;AAIzB,QAAO"}
@@ -2,4 +2,4 @@
2
2
  declare const _default: (fromPath: string) => Promise<any[]>;
3
3
  //#endregion
4
4
  export { _default as default };
5
- //# sourceMappingURL=loadModels.d.mts.map
5
+ //# sourceMappingURL=loadModels.d.ts.map
@@ -27,4 +27,4 @@ var loadModels_default = async (fromPath) => {
27
27
  //#endregion
28
28
  export { loadModels_default as default };
29
29
 
30
- //# sourceMappingURL=loadModels.mjs.map
30
+ //# sourceMappingURL=loadModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadModels.js","names":[],"sources":["../../src/utils/loadModels.ts"],"sourcesContent":["import fs from \"node:fs\"\nimport path from \"node:path\"\n\nexport default async (fromPath: string): Promise<any[]> => {\n\tif (typeof fromPath !== \"string\") {\n\t\treturn []\n\t}\n\n\tif (!fs.existsSync(fromPath)) {\n\t\tconsole.warn(\n\t\t\t`Cannot load models from [${fromPath}] case this path does not exist`,\n\t\t)\n\t\treturn []\n\t}\n\n\tlet mods = []\n\n\tlet files = await fs.promises.readdir(fromPath)\n\n\tfiles = files.filter((file) => file.endsWith(\".js\") || file.endsWith(\".ts\"))\n\n\tfor await (const file of files) {\n\t\tconst name = file.replace(\".js\", \"\")\n\t\tconst file_path = path.join(fromPath, file)\n\n\t\ttry {\n\t\t\tlet mod = await import(file_path)\n\n\t\t\tmod = mod.default\n\n\t\t\tmods.push(mod)\n\t\t} catch (error) {\n\t\t\tconsole.error(`Failed to load model [${name}]:`, error)\n\t\t\tcontinue\n\t\t}\n\t}\n\n\treturn mods\n}\n"],"mappings":";;;AAGA,IAAA,qBAAe,OAAO,aAAqC;AAC1D,KAAI,OAAO,aAAa,SACvB,QAAO,EAAE;AAGV,KAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC7B,UAAQ,KACP,4BAA4B,SAAS,iCACrC;AACD,SAAO,EAAE;;CAGV,IAAI,OAAO,EAAE;CAEb,IAAI,QAAQ,MAAM,GAAG,SAAS,QAAQ,SAAS;AAE/C,SAAQ,MAAM,QAAQ,SAAS,KAAK,SAAS,MAAM,IAAI,KAAK,SAAS,MAAM,CAAC;AAE5E,YAAW,MAAM,QAAQ,OAAO;EAC/B,MAAM,OAAO,KAAK,QAAQ,OAAO,GAAG;EACpC,MAAM,YAAY,KAAK,KAAK,UAAU,KAAK;AAE3C,MAAI;GACH,IAAI,MAAM,MAAM,OAAO;AAEvB,SAAM,IAAI;AAEV,QAAK,KAAK,IAAI;WACN,OAAO;AACf,WAAQ,MAAM,yBAAyB,KAAK,KAAK,MAAM;AACvD;;;AAIF,QAAO"}
@@ -1,4 +1,4 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/utils/queryParser.d.ts
4
4
  declare function queryParser(model: Model<any>, query: any, depth?: number): any;
@@ -6,4 +6,4 @@ declare function isValidFieldName(fields: Record<string, any>, fieldName: string
6
6
  declare function isValidOperator(operator: string): boolean;
7
7
  //#endregion
8
8
  export { queryParser as default, isValidFieldName, isValidOperator };
9
- //# sourceMappingURL=queryParser.d.mts.map
9
+ //# sourceMappingURL=queryParser.d.ts.map
@@ -91,4 +91,4 @@ function isValidOperator(operator) {
91
91
  //#endregion
92
92
  export { queryParser as default, isValidFieldName, isValidOperator };
93
93
 
94
- //# sourceMappingURL=queryParser.mjs.map
94
+ //# sourceMappingURL=queryParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryParser.js","names":["cassandra"],"sources":["../../src/utils/queryParser.ts"],"sourcesContent":["import type { Model } from \"../model\"\n\n// @ts-ignore\nimport cassandra from \"cassandra-driver\"\nconst { q } = cassandra.mapping\n\nconst MAX_QUERY_DEPTH = 3\nconst MAX_IN_ELEMENTS = 1000\n\nconst VALID_OPERATORS = new Set([\n\t\"$eq\",\n\t\"$ne\",\n\t\"$gt\",\n\t\"$gte\",\n\t\"$lt\",\n\t\"$lte\",\n\t\"$in\",\n])\n\nfunction requireNotNull(value: any, operator: string): void {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(\n\t\t\t`${operator} operator cannot compare with null or undefined`,\n\t\t)\n\t}\n}\n\nfunction buildOperator(operator: string, opValue: any): any {\n\tif (!VALID_OPERATORS.has(operator)) {\n\t\tthrow new Error(`Invalid operator: ${operator}`)\n\t}\n\n\tswitch (operator) {\n\t\tcase \"$eq\":\n\t\t\treturn opValue\n\n\t\tcase \"$ne\":\n\t\t\trequireNotNull(opValue, \"$ne\")\n\t\t\treturn q.notEq(opValue)\n\n\t\tcase \"$in\":\n\t\t\tif (!Array.isArray(opValue)) {\n\t\t\t\tthrow new Error(\"$in operator requires an array\")\n\t\t\t}\n\t\t\tif (opValue.length > MAX_IN_ELEMENTS) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`$in operator exceeds maximum of ${MAX_IN_ELEMENTS} elements`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (let i = 0; i < opValue.length; i++) {\n\t\t\t\tif (opValue[i] === null || opValue[i] === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`$in array element at index ${i} cannot be null or undefined`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn q.in_(opValue)\n\n\t\tcase \"$gt\":\n\t\t\trequireNotNull(opValue, \"$gt\")\n\t\t\treturn q.gt(opValue)\n\n\t\tcase \"$gte\":\n\t\t\trequireNotNull(opValue, \"$gte\")\n\t\t\treturn q.gte(opValue)\n\n\t\tcase \"$lt\":\n\t\t\trequireNotNull(opValue, \"$lt\")\n\t\t\treturn q.lt(opValue)\n\n\t\tcase \"$lte\":\n\t\t\trequireNotNull(opValue, \"$lte\")\n\t\t\treturn q.lte(opValue)\n\t}\n}\n\nexport default function queryParser(\n\tmodel: Model<any>,\n\tquery: any,\n\tdepth: number = 0,\n) {\n\tif (depth > MAX_QUERY_DEPTH) {\n\t\tthrow new Error(`Query depth exceeds maximum of ${MAX_QUERY_DEPTH}`)\n\t}\n\n\tif (!query || typeof query !== \"object\") {\n\t\treturn query\n\t}\n\n\tconst parsedQuery: Record<string, any> = {}\n\tconst fields = model.schema.fields\n\n\tfor (const field of Object.keys(query)) {\n\t\tconst value = query[field]\n\n\t\tif (field === \"$and\") {\n\t\t\thandleAnd(model, value, parsedQuery, depth)\n\t\t\tcontinue\n\t\t}\n\n\t\tif (field === \"$or\") {\n\t\t\tthrow new Error(\n\t\t\t\t\"ScyllaDB does not support OR queries across different columns. Use $in for a single column.\",\n\t\t\t)\n\t\t}\n\n\t\tif (!isValidFieldName(fields, field)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid field name: [${field}] or it does not exist in schema`,\n\t\t\t)\n\t\t}\n\n\t\tparsedQuery[field] = parseField(value)\n\t}\n\n\treturn parsedQuery\n}\n\nfunction handleAnd(\n\tmodel: Model<any>,\n\tconditions: any,\n\tparsedQuery: Record<string, any>,\n\tdepth: number,\n) {\n\tif (!Array.isArray(conditions)) {\n\t\tthrow new Error(\"$and operator requires an array\")\n\t}\n\tif (conditions.length > 10) {\n\t\tthrow new Error(\"$and operator exceeds maximum of 10 conditions\")\n\t}\n\n\tfor (let i = 0; i < conditions.length; i++) {\n\t\tconst condition = conditions[i]\n\t\tif (!condition || typeof condition !== \"object\") {\n\t\t\tthrow new Error(`$and condition at index ${i} must be an object`)\n\t\t}\n\n\t\tconst parsed = queryParser(model, condition, depth + 1)\n\t\tfor (const key of Object.keys(parsed)) {\n\t\t\tif (key in parsedQuery) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`$and conflict: field \"${key}\" appears in multiple conditions`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tObject.assign(parsedQuery, parsed)\n\t}\n}\n\nfunction parseField(value: any): any {\n\tif (\n\t\tvalue === null ||\n\t\ttypeof value !== \"object\" ||\n\t\tArray.isArray(value) ||\n\t\tvalue instanceof Date\n\t) {\n\t\tif (Array.isArray(value)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Array values require explicit operator (e.g., $in)\",\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n\n\tconst operators = Object.keys(value)\n\tconst compiledOps = operators.map((op) => buildOperator(op, value[op]))\n\n\treturn compiledOps.length === 1\n\t\t? compiledOps[0]\n\t\t: (q.and as any)(...compiledOps)\n}\n\nexport function isValidFieldName(\n\tfields: Record<string, any>,\n\tfieldName: string,\n): boolean {\n\tconst invalidPatterns = [\n\t\t/^[0-9]/,\n\t\t/[^a-zA-Z0-9_]/,\n\t\t/^(select|insert|update|delete|drop|create|alter|truncate)$/i,\n\t]\n\n\tfor (const pattern of invalidPatterns) {\n\t\tif (pattern.test(fieldName)) return false\n\t}\n\n\treturn fieldName in fields\n}\n\nexport function isValidOperator(operator: string): boolean {\n\treturn VALID_OPERATORS.has(operator)\n}\n"],"mappings":";;AAIA,MAAM,EAAE,MAAMA,UAAU;AAExB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,MAAM,kBAAkB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,SAAS,eAAe,OAAY,UAAwB;AAC3D,KAAI,UAAU,QAAQ,UAAU,KAAA,EAC/B,OAAM,IAAI,MACT,GAAG,SAAS,iDACZ;;AAIH,SAAS,cAAc,UAAkB,SAAmB;AAC3D,KAAI,CAAC,gBAAgB,IAAI,SAAS,CACjC,OAAM,IAAI,MAAM,qBAAqB,WAAW;AAGjD,SAAQ,UAAR;EACC,KAAK,MACJ,QAAO;EAER,KAAK;AACJ,kBAAe,SAAS,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I,CAAC,MAAM,QAAQ,WAAW,CAC7B,OAAM,IAAI,MAAM,kCAAkC;AAEnD,KAAI,WAAW,SAAS,GACvB,OAAM,IAAI,MAAM,iDAAiD;AAGlE,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC3C,MAAM,YAAY,WAAW;AAC7B,MAAI,CAAC,aAAa,OAAO,cAAc,SACtC,OAAM,IAAI,MAAM,2BAA2B,EAAE,oBAAoB;EAGlE,MAAM,SAAS,YAAY,OAAO,WAAW,QAAQ,EAAE;AACvD,OAAK,MAAM,OAAO,OAAO,KAAK,OAAO,CACpC,KAAI,OAAO,YACV,OAAM,IAAI,MACT,yBAAyB,IAAI,kCAC7B;AAGH,SAAO,OAAO,aAAa,OAAO;;;AAIpC,SAAS,WAAW,OAAiB;AACpC,KACC,UAAU,QACV,OAAO,UAAU,YACjB,MAAM,QAAQ,MAAM,IACpB,iBAAiB,MAChB;AACD,MAAI,MAAM,QAAQ,MAAM,CACvB,OAAM,IAAI,MACT,qDACA;AAEF,SAAO;;CAIR,MAAM,cADY,OAAO,KAAK,MACD,CAAC,KAAK,OAAO,cAAc,IAAI,MAAM,IAAI,CAAC;AAEvE,QAAO,YAAY,WAAW,IAC3B,YAAY,KACX,EAAE,IAAY,GAAG,YAAY;;AAGlC,SAAgB,iBACf,QACA,WACU;AAOV,MAAK,MAAM,WAAW;EALrB;EACA;EACA;EAGoC,CACpC,KAAI,QAAQ,KAAK,UAAU,CAAE,QAAO;AAGrC,QAAO,aAAa;;AAGrB,SAAgB,gBAAgB,UAA2B;AAC1D,QAAO,gBAAgB,IAAI,SAAS"}
@@ -1,7 +1,7 @@
1
- import { Model } from "../model/index.mjs";
1
+ import { Model } from "../model/index.js";
2
2
 
3
3
  //#region src/utils/typeChecker.d.ts
4
4
  declare function typeChecker(model: Model<any>, data: any): boolean;
5
5
  //#endregion
6
6
  export { typeChecker as default };
7
- //# sourceMappingURL=typeChecker.d.mts.map
7
+ //# sourceMappingURL=typeChecker.d.ts.map
@@ -1,4 +1,4 @@
1
- import { isValidFieldName } from "./queryParser.mjs";
1
+ import { isValidFieldName } from "./queryParser.js";
2
2
  import Cassandra from "cassandra-driver";
3
3
  //#region src/utils/typeChecker.ts
4
4
  const { types } = Cassandra;
@@ -52,4 +52,4 @@ function typeChecker(model, data) {
52
52
  //#endregion
53
53
  export { typeChecker as default };
54
54
 
55
- //# sourceMappingURL=typeChecker.mjs.map
55
+ //# sourceMappingURL=typeChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeChecker.js","names":["cassandra"],"sources":["../../src/utils/typeChecker.ts"],"sourcesContent":["// @ts-ignore\nimport cassandra from \"cassandra-driver\"\nconst { types } = cassandra\nimport type { Model } from \"../model\"\nimport { isValidFieldName } from \"./queryParser\"\n\nconst stringTypes = new Set([\"ascii\", \"text\", \"varchar\", \"inet\"])\nconst intTypes = new Set([\"int\", \"smallint\", \"tinyint\"])\nconst floatTypes = new Set([\"double\", \"float\"])\nconst longTypes = new Set([\"bigint\", \"counter\"])\n\nfunction isValidValue(value: any, expectedType: string): boolean {\n\tif (value === null || value === undefined) return true\n\n\tif (stringTypes.has(expectedType)) return typeof value === \"string\"\n\tif (intTypes.has(expectedType)) return Number.isInteger(value)\n\tif (floatTypes.has(expectedType)) return typeof value === \"number\"\n\tif (longTypes.has(expectedType)) {\n\t\treturn (\n\t\t\ttypeof value === \"bigint\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\tvalue instanceof types.Long\n\t\t)\n\t}\n\n\tswitch (expectedType) {\n\t\tcase \"boolean\":\n\t\t\treturn typeof value === \"boolean\"\n\t\tcase \"decimal\":\n\t\t\treturn (\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\ttypeof value === \"string\" ||\n\t\t\t\tvalue instanceof types.BigDecimal\n\t\t\t)\n\t\tcase \"varint\":\n\t\t\treturn (\n\t\t\t\ttypeof value === \"bigint\" ||\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\tvalue instanceof types.Integer\n\t\t\t)\n\t\tcase \"timestamp\":\n\t\t\treturn (\n\t\t\t\tvalue instanceof Date ||\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\ttypeof value === \"string\"\n\t\t\t)\n\t\tcase \"date\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.LocalDate\n\t\tcase \"time\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.LocalTime\n\t\tcase \"uuid\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.Uuid\n\t\tcase \"timeuuid\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.TimeUuid\n\t\tcase \"blob\":\n\t\t\treturn Buffer.isBuffer(value) || value instanceof Uint8Array\n\t}\n\n\tif (expectedType.startsWith(\"list<\") || expectedType.startsWith(\"set<\")) {\n\t\treturn Array.isArray(value) || value instanceof Set\n\t}\n\tif (expectedType.startsWith(\"map<\")) {\n\t\treturn (\n\t\t\ttypeof value === \"object\" && !Array.isArray(value) && value !== null\n\t\t)\n\t}\n\n\treturn false\n}\n\nexport default function typeChecker(model: Model<any>, data: any): boolean {\n\tif (!data || typeof data !== \"object\" || Array.isArray(data)) {\n\t\tthrow new TypeError(\n\t\t\t`[${model.name}] Validation error: Data payload must be an object`,\n\t\t)\n\t}\n\n\tconst fields = model.schema.fields\n\n\tfor (const [key, value] of Object.entries(data)) {\n\t\tif (!isValidFieldName(fields, key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`[${model.name}] Validation error: Field '${key}' does not exist in schema`,\n\t\t\t)\n\t\t}\n\n\t\tconst fieldConfig = fields[key]\n\t\tconst expectedType = (fieldConfig.type || \"text\").toLowerCase()\n\n\t\tif (!isValidValue(value, expectedType)) {\n\t\t\tconst receivedType = Array.isArray(value) ? \"array\" : typeof value\n\t\t\tthrow new TypeError(\n\t\t\t\t`[${model.name}] Validation error: Invalid type for field '${key}'. ` +\n\t\t\t\t\t`Expected[${expectedType}], but received [${receivedType}]`,\n\t\t\t)\n\t\t}\n\t}\n\n\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I,aAAa,WAAW,OAAO,CACtE,QAAO,MAAM,QAAQ,MAAM,IAAI,iBAAiB;AAEjD,KAAI,aAAa,WAAW,OAAO,CAClC,QACC,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,MAAM,IAAI,UAAU;AAIlE,QAAO;;AAGR,SAAwB,YAAY,OAAmB,MAAoB;AAC1E,KAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK,CAC3D,OAAM,IAAI,UACT,IAAI,MAAM,KAAK,oDACf;CAGF,MAAM,SAAS,MAAM,OAAO;AAE5B,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,EAAE;AAChD,MAAI,CAAC,iBAAiB,QAAQ,IAAI,CACjC,OAAM,IAAI,MACT,IAAI,MAAM,KAAK,6BAA6B,IAAI,4BAChD;EAIF,MAAM,gBADc,OAAO,KACO,QAAQ,QAAQ,aAAa;AAE/D,MAAI,CAAC,aAAa,OAAO,aAAa,EAAE;GACvC,MAAM,eAAe,MAAM,QAAQ,MAAM,GAAG,UAAU,OAAO;AAC7D,SAAM,IAAI,UACT,IAAI,MAAM,KAAK,8CAA8C,IAAI,cACpD,aAAa,mBAAmB,aAAa,GAC1D;;;AAIH,QAAO"}
package/client.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.mjs","names":["loadModels","buildMapper"],"sources":["../src/client.ts"],"sourcesContent":["import type {\n\tClient as T_CassandraClient,\n\tClientOptions as T_CassandraClientOptions,\n\tmapping as T_CassandraMapping,\n} from \"cassandra-driver\"\nimport type { ClientConfig } from \"./types\"\n\n//@ts-ignore\nimport path from \"node:path\"\n//@ts-ignore\nimport Cassandra from \"cassandra-driver\"\nimport loadModels from \"./utils/loadModels\"\nimport buildMapper from \"./utils/buildMapper\"\n\nimport { Model } from \"./model\"\nimport { InferDocument } from \"./types\"\n\nconst DEFAULT_MAX_RETRIES = 3\nconst DEFAULT_RETRY_DELAY = 1000\nconst { SCYLLA_CONTACT_POINTS, SCYLLA_LOCAL_DATA_CENTER, SCYLLA_KEYSPACE } =\n\tprocess.env\n\nexport class Client {\n\tconstructor(config: ClientConfig = {}) {\n\t\tif (globalThis.__scylla_client) {\n\t\t\tthrow new Error(\n\t\t\t\t\"An instance of Scylla Client is already initialized\",\n\t\t\t)\n\t\t}\n\n\t\tthis.config = {\n\t\t\tmodelsPath: path.resolve(process.cwd(), \"db\"),\n\t\t\tcontactPoints:\n\t\t\t\t(config.contactPoints ?? SCYLLA_CONTACT_POINTS)\n\t\t\t\t\t? SCYLLA_CONTACT_POINTS.split(\",\")\n\t\t\t\t\t: [\"127.0.0.1\"],\n\t\t\tlocalDataCenter:\n\t\t\t\tconfig.localDataCenter ??\n\t\t\t\tSCYLLA_LOCAL_DATA_CENTER ??\n\t\t\t\t\"datacenter1\",\n\t\t\tkeyspace: config.keyspace ?? SCYLLA_KEYSPACE ?? \"default\",\n\t\t\tport: 9042,\n\t\t\tmaxRetries: DEFAULT_MAX_RETRIES,\n\t\t\tretryDelay: DEFAULT_RETRY_DELAY,\n\t\t\t...config,\n\t\t}\n\n\t\tconst clientOptions: T_CassandraClientOptions = {\n\t\t\tcontactPoints: this.config.contactPoints,\n\t\t\tlocalDataCenter: this.config.localDataCenter,\n\t\t\tkeyspace: this.config.keyspace,\n\t\t\tprotocolOptions: {\n\t\t\t\tport: this.config.port,\n\t\t\t},\n\t\t}\n\n\t\tif (this.config.pooling) {\n\t\t\tclientOptions.pooling = this.config.pooling\n\t\t}\n\n\t\tthis.driver = new Cassandra.Client(clientOptions)\n\t}\n\n\tconfig: ClientConfig\n\tdriver: T_CassandraClient\n\tmapper: T_CassandraMapping.Mapper\n\tmodels: Map<string, Model<any>> = new Map()\n\n\tasync initialize(options: { sync?: boolean } = {}) {\n\t\tlet models: Model<any>[]\n\n\t\ttry {\n\t\t\tmodels = await loadModels(this.config.modelsPath)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to load models: ${error.message}`)\n\t\t}\n\n\t\tmodels = models.filter((schema) => schema instanceof Model)\n\n\t\tthis.mapper = new Cassandra.mapping.Mapper(this.driver, {\n\t\t\tmodels: buildMapper(models),\n\t\t})\n\n\t\tfor (let model of models) {\n\t\t\tthis.models.set(\n\t\t\t\tmodel.name,\n\t\t\t\tmodel as Model<InferDocument<typeof model.schema>>,\n\t\t\t)\n\n\t\t\tif (options?.sync === true) {\n\t\t\t\tawait model._sync()\n\t\t\t}\n\t\t}\n\n\t\tglobalThis.__scylla_client = this\n\n\t\tconsole.log(\"Connecting to ScyllaDB\")\n\t\tawait this.connectWithRetry()\n\t\tconsole.log(\"ScyllaDB Connected\")\n\t}\n\n\tprivate async connectWithRetry(): Promise<void> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\tawait this.driver.connect()\n\t\t\t\treturn\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Connection attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t)\n\n\t\t\t\tif (attempt < this.config.maxRetries!) {\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Failed to connect to ScyllaDB after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate delay(ms: number): Promise<void> {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms))\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.driver.shutdown()\n\t\t\tconsole.log(\"ScyllaDB connection closed\")\n\n\t\t\tdelete globalThis.__scylla_client\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error shutting down ScyllaDB connection:\", error)\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync executeWithRetry<T>(\n\t\toperation: () => Promise<T>,\n\t\toperationName: string = \"operation\",\n\t): Promise<T> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn await operation()\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\n\t\t\t\t// check if error is retryable\n\t\t\t\tif (\n\t\t\t\t\tthis.isRetryableError(error) &&\n\t\t\t\t\tattempt < this.config.maxRetries!\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Operation ${operationName} attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t\t)\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t// if not retryable or last attempt, throw\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Operation ${operationName} failed after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate isRetryableError(error: any): boolean {\n\t\t// retry on network errors, timeouts, and certain ScyllaDB errors\n\t\tconst retryableMessages = [\n\t\t\t\"timeout\",\n\t\t\t\"connection\",\n\t\t\t\"network\",\n\t\t\t\"unavailable\",\n\t\t\t\"overloaded\",\n\t\t\t\"no hosts available\",\n\t\t]\n\n\t\tconst errorMessage = error.message?.toLowerCase() || \"\"\n\n\t\treturn retryableMessages.some((msg) => errorMessage.includes(msg))\n\t}\n}\n\nexport default Client\n"],"mappings":";;;;;;AAiBA,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,EAAE,uBAAuB,0BAA0B,oBACxD,QAAQ;AAET,IAAa,SAAb,MAAoB;CACnB,YAAY,SAAuB,EAAE,EAAE;AACtC,MAAI,WAAW,gBACd,OAAM,IAAI,MACT,sDACA;AAGF,OAAK,SAAS;GACb,YAAY,KAAK,QAAQ,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AAW,MAAM,UAC/C;AAED,OAAI,UAAU,KAAK,OAAO,YAAa;AACtC,YAAQ,IAAI,eAAe,KAAK,OAAO,WAAW,OAAO;AACzD,UAAM,KAAK,MAAM,KAAK,OAAO,WAAY;;;AAK5C,QAAM,IAAI,MACT,uCAAuC,KAAK,OAAO,WAAW,aAAa,WAAW,UACtF;;CAGF,MAAc,IAA2B;AACxC,SAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;;CAGzD,MAAM,WAA0B;AAC/B,MAAI;AACH,SAAM,KAAK,OAAO,UAAU;AAC5B,WAAQ,IAAI,6BAA6B;AAEzC,UAAO,WAAW;WACV,OAAO;AACf,WAAQ,MAAM,4CAA4C,MAAM;AAChE,SAAM;;;CAIR,MAAM,iBACL,WACA,gBAAwB,aACX;EACb,IAAI,YAA0B;AAE9B,OAAK,IAAI,UAAU,GAAG,WAAW,KAAK,OAAO,YAAa,UACzD,KAAI;AACH,UAAO,MAAM,WAAW;WAChB,OAAO;AACf,eAAY;AAGZ,OACC,KAAK,iBAAiB,MAAM,IAC5B,UAAU,KAAK,OAAO,YACrB;AACD,YAAQ,KACP,aAAa,cAAc,WAAW,QAAQ,WAAW,MAAM,UAC/D;AACD,YAAQ,IAAI,eAAe,KAAK,OAAO,WAAW,OAAO;AAEzD,UAAM,KAAK,MAAM,KAAK,OAAO,WAAY;AACzC;;AAID,SAAM;;AAIR,QAAM,IAAI,MACT,aAAa,cAAc,gBAAgB,KAAK,OAAO,WAAW,aAAa,WAAW,UAC1F;;CAGF,iBAAyB,OAAqB;EAE7C,MAAM,oBAAoB;GACzB;GACA;GACA;GACA;GACA;GACA;GACA;EAED,MAAM,eAAe,MAAM,SAAS,aAAa,IAAI;AAErD,SAAO,kBAAkB,MAAM,QAAQ,aAAa,SAAS,IAAI,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"create_table.mjs","names":[],"sources":["../../src/cql_gen/create_table.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default function (model: Model): string {\n\tconst desc = model.schema\n\tconst tableName = desc.table_name\n\tconst keyspace = model.client.config.keyspace\n\tconst fields = desc.fields\n\tconst key = desc.keys\n\tconst clusteringOrder = desc.clustering_order\n\n\tlet columnsDef = \"\"\n\n\tfor (const fieldName in fields) {\n\t\tconst field = fields[fieldName]\n\t\tconst typeStr = typeof field === \"string\" ? field : (field as any)?.type\n\n\t\tif (!typeStr) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid field type for \"${fieldName}\" in model \"${tableName}\"`,\n\t\t\t)\n\t\t}\n\n\t\tcolumnsDef += `\"${fieldName}\" ${typeStr.toUpperCase()}, `\n\t}\n\n\tlet pkDef = \"\"\n\n\tif (typeof key === \"string\") {\n\t\tpkDef = `\"${key}\"`\n\t} else if (Array.isArray(key) && key.length > 0) {\n\t\tconst first = key[0]\n\n\t\tif (Array.isArray(first)) {\n\t\t\tpkDef = `(${first.map((k) => `\"${k}\"`).join(\", \")})`\n\t\t} else {\n\t\t\tpkDef = `\"${first}\"`\n\t\t}\n\n\t\tfor (let i = 1; i < key.length; i++) {\n\t\t\tpkDef += `, \"${key[i]}\"`\n\t\t}\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Missing or invalid primary key in model \"${tableName}\"`,\n\t\t)\n\t}\n\n\tlet clusterClause = \"\"\n\n\tif (clusteringOrder) {\n\t\tlet orderDef = \"\"\n\n\t\tfor (const col in clusteringOrder) {\n\t\t\tif (orderDef !== \"\") {\n\t\t\t\torderDef += \", \"\n\t\t\t}\n\n\t\t\torderDef += `\"${col}\" ${(clusteringOrder[col] as string).toUpperCase()}`\n\t\t}\n\t\tif (orderDef !== \"\") {\n\t\t\tclusterClause = ` WITH CLUSTERING ORDER BY (${orderDef})`\n\t\t}\n\t}\n\n\treturn `CREATE TABLE IF NOT EXISTS ${keyspace}.${tableName} (${columnsDef}PRIMARY KEY (${pkDef}))${clusterClause}`\n}\n"],"mappings":";AAEA,SAAA,qBAAyB,OAAsB;CAC9C,MAAM,OAAO,MAAM;CACnB,MAAM,YAAY,KAAK;CACvB,MAAM,WAAW,MAAM,OAAO,OAAO;CACrC,MAAM,SAAS,KAAK;CACpB,MAAM,MAAM,KAAK;CACjB,MAAM,kBAAkB,KAAK;CAE7B,IAAI,aAAa;AAEjB,MAAK,MAAM,aAAa,QAAQ;EAC/B,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,OAAO,UAAU,WAAW,QAAS,OAAe;AAEpE,MAAI,CAAC,QACJ,OAAM,IAAI,MACT,2BAA2B,UAAU,cAAc,UAAU,GAC7D;AAGF,gBAAc,IAAI,UAAU,IAAI,QAAQ,aAAa,CAAC;;CAGvD,IAAI,QAAQ;AAEZ,KAAI,OAAO,QAAQ,SAClB,SAAQ,IAAI,IAAI;UACN,MAAM,QAAQ,IAAI,IAAI,IAAI,SAAS,GAAG;EAChD,MAAM,QAAQ,IAAI;AAElB,MAAI,MAAM,QAAQ,MAAM,CACvB,SAAQ,IAAI,MAAM,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC;MAElD,SAAQ,IAAI,MAAM;AAGnB,OAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC/B,UAAS,MAAM,IAAI,GAAG;OAGvB,OAAM,IAAI,MACT,4CAA4C,UAAU,GACtD;CAGF,IAAI,gBAAgB;AAEpB,KAAI,iBAAiB;EACpB,IAAI,WAAW;AAEf,OAAK,MAAM,OAAO,iBAAiB;AAClC,OAAI,aAAa,GAChB,aAAY;AAGb,eAAY,IAAI,IAAI,IAAK,gBAAgB,KAAgB,aAAa;;AAEvE,MAAI,aAAa,GAChB,iBAAgB,8BAA8B,SAAS;;AAIzD,QAAO,8BAA8B,SAAS,GAAG,UAAU,IAAI,WAAW,eAAe,MAAM,IAAI"}
package/index.d.mts DELETED
@@ -1,6 +0,0 @@
1
- import { Schema } from "./schema/index.mjs";
2
- import { Model } from "./model/index.mjs";
3
- import { Result } from "./result/index.mjs";
4
- import { ColumnTypes } from "./types.mjs";
5
- import { Client } from "./client.mjs";
6
- export { Client, Client as default, ColumnTypes, Model, Result, Schema };
package/index.mjs DELETED
@@ -1,11 +0,0 @@
1
- import { Result } from "./result/index.mjs";
2
- import { Model } from "./model/index.mjs";
3
- import { Client } from "./client.mjs";
4
- import { Schema } from "./schema/index.mjs";
5
- import { ColumnTypes } from "./types.mjs";
6
- //#region src/index.ts
7
- var src_default = Client;
8
- //#endregion
9
- export { Client, ColumnTypes, Model, Result, Schema, src_default as default };
10
-
11
- //# sourceMappingURL=index.mjs.map
package/index.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import Client from \"./client\"\nimport Model from \"./model\"\nimport Schema from \"./schema\"\nimport Result from \"./result\"\nimport { ColumnTypes } from \"./types\"\n\nexport default Client\nexport { Client, Model, Schema, Result, ColumnTypes }\n"],"mappings":";;;;;;AAMA,IAAA,cAAe"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":["findOneOP","updateOP","deleteOP","countAllOP","tableExistsOP"],"sources":["../../src/model/index.ts"],"sourcesContent":["import Client from \"..\"\nimport { Result } from \"../result\"\n\nimport fillDefaults from \"../utils/fillDefaults\"\n\nimport { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { DocumentResult, Query, QueryOptions } from \"../types\"\nimport type { Schema } from \"../schema\"\n\nimport findOneOP from \"../operations/findOne\"\nimport findOP from \"../operations/find\"\nimport updateOP from \"../operations/update\"\nimport deleteOP from \"../operations/delete\"\nimport countAllOP from \"../operations/countAll\"\n\nimport tableExistsOP from \"../operations/tableExists\"\nimport syncOP from \"../operations/sync\"\n\nexport class Model<TDoc = any> {\n\tname: string\n\tschema: Schema<any>\n\n\tget client(): Client {\n\t\treturn globalThis.__scylla_client\n\t}\n\n\tget mapper(): mapping.ModelMapper {\n\t\tif (!globalThis.__scylla_client?.mapper) {\n\t\t\tthrow new Error(\"No mapper available\")\n\t\t}\n\n\t\treturn globalThis.__scylla_client.mapper.forModel(this.name)\n\t}\n\n\tconstructor(name: string, schema: Schema<any>) {\n\t\tthis.name = name\n\t\tthis.schema = schema\n\n\t\tif (!Array.isArray(this.schema.keys)) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"keys\" array`)\n\t\t}\n\t\tif (!this.schema.table_name) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"table_name\"`)\n\t\t}\n\t\tif (!this.schema.fields || typeof this.schema.fields !== \"object\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[${this.name}] model has missing or invalid \"fields\"`,\n\t\t\t)\n\t\t}\n\t}\n\n\tcreate = (data: Partial<TDoc>) => this._wrap(data)\n\n\tfind: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc[]>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>[]>\n\t} = findOP.bind(this)\n\n\tfindOne: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>>\n\t} = findOneOP.bind(this)\n\n\tupdate: (query: Query<TDoc>) => Promise<DocumentResult<TDoc>> =\n\t\tupdateOP.bind(this)\n\n\tdelete: (query: Query<TDoc>) => Promise<mapping.Result> =\n\t\tdeleteOP.bind(this)\n\n\tcountAll: () => Promise<number> = countAllOP.bind(this)\n\n\t_sync: typeof syncOP = syncOP.bind(this)\n\t_tableExists: typeof tableExistsOP = tableExistsOP.bind(this)\n\n\t_wrap(row: any): DocumentResult<TDoc> | null {\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\n\t\trow = fillDefaults(this.schema, row)\n\n\t\treturn new Result<TDoc>(row, this) as DocumentResult<TDoc>\n\t}\n}\n\nexport default Model\n"],"mappings":";;;;;;;;;;AAkBA,IAAa,QAAb,MAA+B;CAC9B;CACA;CAEA,IAAI,SAAiB;AACpB,SAAO,WAAW;;CAGnB,IAAI,SAA8B;AACjC,MAAI,CAAC,WAAW,iBAAiB,OAChC,OAAM,IAAI,MAAM,sBAAsB;AAGvC,SAAO,WAAW,gBAAgB,OAAO,SAAS,KAAK,KAAK;;CAG7D,YAAY,MAAc,QAAqB;AAC9C,OAAK,OAAO;AACZ,OAAK,SAAS;AAEd,MAAI,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,CACnC,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,WAChB,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,UAAU,OAAO,KAAK,OAAO,WAAW,SACxD,OAAM,IAAI,MACT,IAAI,KAAK,KAAK,yCACd;;CAIH,UAAU,SAAwB,KAAK,MAAM,KAAK;CAElD,OASI,OAAO,KAAK,KAAK;CAErB,UASIA,gBAAU,KAAK,KAAK;CAExB,SACCC,eAAS,KAAK,KAAK;CAEpB,SACCC,eAAS,KAAK,KAAK;CAEpB,WAAkCC,iBAAW,KAAK,KAAK;CAEvD,QAAuB,OAAO,KAAK,KAAK;CACxC,eAAqCC,oBAAc,KAAK,KAAK;CAE7D,MAAM,KAAuC;AAC5C,MAAI,CAAC,IACJ,QAAO;AAGR,QAAM,aAAa,KAAK,QAAQ,IAAI;AAEpC,SAAO,IAAI,OAAa,KAAK,KAAK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"countAll.mjs","names":[],"sources":["../../src/operations/countAll.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model, timeoutMs: number = 60000) {\n\tconst cql = `SELECT COUNT(1) FROM ${this.client.config.keyspace}.${this.schema.table_name}`\n\n\tconst queryOptions = {\n\t\tprepare: true,\n\t\treadTimeout: timeoutMs,\n\t}\n\n\tconst operation = async () => {\n\t\tconst result = await this.client.driver.execute(cql, [], queryOptions)\n\n\t\treturn result.rows[0].count.toNumber()\n\t}\n\n\treturn this.client.executeWithRetry(operation, `countAll on ${this.name}`)\n}\n"],"mappings":";AAEA,eAAA,iBAA4C,YAAoB,KAAO;CACtE,MAAM,MAAM,wBAAwB,KAAK,OAAO,OAAO,SAAS,GAAG,KAAK,OAAO;CAE/E,MAAM,eAAe;EACpB,SAAS;EACT,aAAa;EACb;CAED,MAAM,YAAY,YAAY;AAG7B,UAAO,MAFc,KAAK,OAAO,OAAO,QAAQ,KAAK,EAAE,EAAE,aAAa,EAExD,KAAK,GAAG,MAAM,UAAU;;AAGvC,QAAO,KAAK,OAAO,iBAAiB,WAAW,eAAe,KAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"delete.mjs","names":[],"sources":["../../src/operations/delete.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model, query: any) {\n\tconst operation = async () => {\n\t\treturn await this.mapper.remove(query)\n\t}\n\n\treturn this.client.executeWithRetry(operation, `delete on ${this.name}`)\n}\n"],"mappings":";AAEA,eAAA,eAA4C,OAAY;CACvD,MAAM,YAAY,YAAY;AAC7B,SAAO,MAAM,KAAK,OAAO,OAAO,MAAM;;AAGvC,QAAO,KAAK,OAAO,iBAAiB,WAAW,aAAa,KAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"find.mjs","names":[],"sources":["../../src/operations/find.ts"],"sourcesContent":["import type Model from \"../model\"\nimport type { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { Query, QueryOptions } from \"../types\"\nimport queryParser from \"../utils/queryParser\"\n\nexport default async function findOP<TDoc>(\n\tthis: Model<TDoc>,\n\tquery: Query<TDoc> = {},\n\toptions?: QueryOptions,\n) {\n\tconst { $limit, $orderby, ...rest } = query\n\n\tlet parsedQuery = queryParser(this, rest)\n\n\tconst docInfo: mapping.FindDocInfo = {}\n\n\tif ($limit !== undefined) {\n\t\tif (typeof $limit !== \"number\" || $limit <= 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`{$limit} operator must be a number greater than 0`,\n\t\t\t)\n\t\t}\n\t\tdocInfo.limit = $limit\n\t}\n\n\tif ($orderby !== undefined) {\n\t\tdocInfo.orderBy = $orderby as Record<string, \"asc\" | \"desc\">\n\t}\n\n\tconst operation = async () => {\n\t\tconst result = await this.mapper.find(parsedQuery, docInfo)\n\t\tconst rows = result.toArray()\n\n\t\tif (options?.raw === true) {\n\t\t\treturn rows\n\t\t}\n\n\t\treturn rows.map((row) => this._wrap(row))\n\t}\n\n\treturn this.client.executeWithRetry(operation, `find on ${this.name}`)\n}\n"],"mappings":";;AAKA,eAA8B,OAE7B,QAAqB,EAAE,EACvB,SACC;CACD,MAAM,EAAE,QAAQ,UAAU,GAAG,SAAS;CAEtC,IAAI,cAAc,YAAY,MAAM,KAAK;CAEzC,MAAM,UAA+B,EAAE;AAEvC,KAAI,WAAW,KAAA,GAAW;AACzB,MAAI,OAAO,WAAW,YAAY,UAAU,EAC3C,OAAM,IAAI,UACT,oDACA;AAEF,UAAQ,QAAQ;;AAGjB,KAAI,aAAa,KAAA,EAChB,SAAQ,UAAU;CAGnB,MAAM,YAAY,YAAY;EAE7B,MAAM,QAAO,MADQ,KAAK,OAAO,KAAK,aAAa,QAAQ,EACvC,SAAS;AAE7B,MAAI,SAAS,QAAQ,KACpB,QAAO;AAGR,SAAO,KAAK,KAAK,QAAQ,KAAK,MAAM,IAAI,CAAC;;AAG1C,QAAO,KAAK,OAAO,iBAAiB,WAAW,WAAW,KAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"findOne.mjs","names":[],"sources":["../../src/operations/findOne.ts"],"sourcesContent":["import type { QueryOptions } from \"../types\"\nimport type Model from \"../model\"\nimport queryParser from \"../utils/queryParser\"\n\nexport default function (this: Model, query: any, options?: QueryOptions) {\n\tquery = queryParser(this, query)\n\n\tconst operation = async () => {\n\t\tlet result = await this.mapper.get(query)\n\n\t\tif (!result) {\n\t\t\treturn null\n\t\t}\n\n\t\tresult = this._wrap(result)\n\n\t\tif (options?.raw === true) {\n\t\t\treturn result.toRaw()\n\t\t}\n\n\t\treturn result\n\t}\n\n\treturn this.client.executeWithRetry(operation, `findOne on ${this.name}`)\n}\n"],"mappings":";;AAIA,SAAA,gBAAsC,OAAY,SAAwB;AACzE,SAAQ,YAAY,MAAM,MAAM;CAEhC,MAAM,YAAY,YAAY;EAC7B,IAAI,SAAS,MAAM,KAAK,OAAO,IAAI,MAAM;AAEzC,MAAI,CAAC,OACJ,QAAO;AAGR,WAAS,KAAK,MAAM,OAAO;AAE3B,MAAI,SAAS,QAAQ,KACpB,QAAO,OAAO,OAAO;AAGtB,SAAO;;AAGR,QAAO,KAAK,OAAO,iBAAiB,WAAW,cAAc,KAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"sync.mjs","names":["generateCreateTableCQL"],"sources":["../../src/operations/sync.ts"],"sourcesContent":["import type Model from \"../model\"\nimport generateCreateTableCQL from \"../cql_gen/create_table\"\n\nexport default async function syncOP(this: Model) {\n\tconst tableExists = await this._tableExists()\n\n\tif (tableExists) {\n\t\treturn\n\t}\n\n\ttry {\n\t\tawait this.client.driver.execute(generateCreateTableCQL(this))\n\n\t\tconsole.log(`Table \"${this.schema.table_name}\" created successfully`)\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`Failed to create table \"${this.schema.table_name}\":`,\n\t\t\terror,\n\t\t)\n\t\tthrow error\n\t}\n}\n"],"mappings":";;AAGA,eAA8B,SAAoB;AAGjD,KAAI,MAFsB,KAAK,cAAc,CAG5C;AAGD,KAAI;AACH,QAAM,KAAK,OAAO,OAAO,QAAQA,qBAAuB,KAAK,CAAC;AAE9D,UAAQ,IAAI,UAAU,KAAK,OAAO,WAAW,wBAAwB;UAC7D,OAAO;AACf,UAAQ,MACP,2BAA2B,KAAK,OAAO,WAAW,KAClD,MACA;AACD,QAAM"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tableExists.mjs","names":[],"sources":["../../src/operations/tableExists.ts"],"sourcesContent":["import type Model from \"../model\"\n\nexport default async function (this: Model) {\n\tconst cql = `\n\t\t\tSELECT table_name\n\t\t\tFROM system_schema.tables\n\t\t\tWHERE keyspace_name = ?\n\t\t\tAND table_name = ?\n\t\t`\n\n\ttry {\n\t\tconst result = await this.client.driver.execute(\n\t\t\tcql,\n\t\t\t[this.client.config.keyspace, this.schema.table_name],\n\t\t\t{\n\t\t\t\tprepare: true,\n\t\t\t},\n\t\t)\n\n\t\treturn result.rows.length > 0\n\t} catch (error) {\n\t\tconsole.error(\n\t\t\t`Failed to check if table \"${this.schema.table_name}\" exists:`,\n\t\t\terror,\n\t\t)\n\n\t\treturn false\n\t}\n}\n"],"mappings":";AAEA,eAAA,sBAA4C;CAC3C,MAAM,MAAM;;;;;;AAOZ,KAAI;AASH,UAAO,MARc,KAAK,OAAO,OAAO,QACvC,KACA,CAAC,KAAK,OAAO,OAAO,UAAU,KAAK,OAAO,WAAW,EACrD,EACC,SAAS,MACT,CACD,EAEa,KAAK,SAAS;UACpB,OAAO;AACf,UAAQ,MACP,6BAA6B,KAAK,OAAO,WAAW,YACpD,MACA;AAED,SAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.mjs","names":[],"sources":["../../src/operations/update.ts"],"sourcesContent":["import type Model from \"../model\"\nimport fillDefaults from \"../utils/fillDefaults\"\nimport typeChecker from \"../utils/typeChecker\"\n\nexport default async function (this: Model, query: any) {\n\tquery = fillDefaults(this.schema, query)\n\n\ttypeChecker(this, query)\n\n\tif (typeof query.__v !== \"undefined\") {\n\t\tif (Number.isNaN(query.__v)) {\n\t\t\tquery.__v = 0\n\t\t} else {\n\t\t\tquery.__v = query.__v + 1\n\t\t}\n\t}\n\n\tconst operation = async () => {\n\t\tawait this.mapper.update(query)\n\t\treturn this._wrap(query)\n\t}\n\n\treturn this.client.executeWithRetry(operation, `update on ${this.name}`)\n}\n"],"mappings":";;;AAIA,eAAA,eAA4C,OAAY;AACvD,SAAQ,aAAa,KAAK,QAAQ,MAAM;AAExC,aAAY,MAAM,MAAM;AAExB,KAAI,OAAO,MAAM,QAAQ,YACxB,KAAI,OAAO,MAAM,MAAM,IAAI,CAC1B,OAAM,MAAM;KAEZ,OAAM,MAAM,MAAM,MAAM;CAI1B,MAAM,YAAY,YAAY;AAC7B,QAAM,KAAK,OAAO,OAAO,MAAM;AAC/B,SAAO,KAAK,MAAM,MAAM;;AAGzB,QAAO,KAAK,OAAO,iBAAiB,WAAW,aAAa,KAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/result/index.ts"],"sourcesContent":["import type { Model } from \"../model\"\nimport typeChecker from \"../utils/typeChecker\"\n\nexport class Result<TDoc = any> {\n\tconstructor(data: TDoc, model: Model<TDoc>) {\n\t\tif (data == null) {\n\t\t\tthrow new Error(\"Cannot create Result with null or undefined data\")\n\t\t}\n\n\t\tif (typeof data !== \"object\" || Array.isArray(data)) {\n\t\t\tthrow new Error(\"Result data must be an object\")\n\t\t}\n\n\t\tObject.assign(this, data)\n\n\t\tObject.defineProperty(this, \"_model\", {\n\t\t\tvalue: model,\n\t\t\tenumerable: false,\n\t\t\twritable: false,\n\t\t\tconfigurable: false,\n\t\t})\n\t}\n\n\t_model: Model<TDoc>\n\n\tasync save() {\n\t\ttry {\n\t\t\tconst data = this.toRaw()\n\n\t\t\ttypeChecker(this._model, data)\n\n\t\t\treturn await this._model.update(data as any)\n\t\t} catch (error: any) {\n\t\t\tthrow new Error(`Failed to save result: ${error.message}`)\n\t\t}\n\t}\n\n\tasync delete() {\n\t\ttry {\n\t\t\treturn await this._model.delete(this.toRaw() as any)\n\t\t} catch (error: any) {\n\t\t\tthrow new Error(`Failed to delete result: ${error.message}`)\n\t\t}\n\t}\n\n\ttoRaw(): TDoc {\n\t\tconst raw: any = {}\n\n\t\tfor (const key in this) {\n\t\t\tif (key === \"_model\") continue\n\n\t\t\tif (this.propertyIsEnumerable(key)) {\n\t\t\t\tconst value = (this as any)[key]\n\n\t\t\t\ttry {\n\t\t\t\t\tJSON.stringify(value)\n\t\t\t\t\traw[key] = value\n\t\t\t\t} catch (error) {\n\t\t\t\t\traw[key] = String(value)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn raw as TDoc\n\t}\n\n\tisValid(): boolean {\n\t\ttry {\n\t\t\ttypeChecker(this._model, this.toRaw())\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\tgetChangedFields(original: Partial<TDoc>): (keyof TDoc)[] {\n\t\tconst current = this.toRaw() as Record<string, any>\n\t\tconst changed: (keyof TDoc)[] = []\n\n\t\tfor (const key in current) {\n\t\t\tif (!(key in original) || current[key] !== (original as any)[key]) {\n\t\t\t\tchanged.push(key as keyof TDoc)\n\t\t\t}\n\t\t}\n\n\t\treturn changed\n\t}\n}\n\nexport default Result\n"],"mappings":";;AAGA,IAAa,SAAb,MAAgC;CAC/B,YAAY,MAAY,OAAoB;AAC3C,MAAI,QAAQ,KACX,OAAM,IAAI,MAAM,mDAAmD;AAGpE,MAAI,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK,CAClD,OAAM,IAAI,MAAM,gCAAgC;AAGjD,SAAO,OAAO,MAAM,KAAK;AAEzB,SAAO,eAAe,MAAM,UAAU;GACrC,OAAO;GACP,YAAY;GACZ,UAAU;GACV,cAAc;GACd,CAAC;;CAGH;CAEA,MAAM,OAAO;AACZ,MAAI;GACH,MAAM,OAAO,KAAK,OAAO;AAEzB,eAAY,KAAK,QAAQ,KAAK;AAE9B,UAAO,MAAM,KAAK,OAAO,OAAO,KAAY;WACpC,OAAY;AACpB,SAAM,IAAI,MAAM,0BAA0B,MAAM,UAAU;;;CAI5D,MAAM,SAAS;AACd,MAAI;AACH,UAAO,MAAM,KAAK,OAAO,OAAO,KAAK,OAAO,CAAQ;WAC5C,OAAY;AACpB,SAAM,IAAI,MAAM,4BAA4B,MAAM,UAAU;;;CAI9D,QAAc;EACb,MAAM,MAAW,EAAE;AAEnB,OAAK,MAAM,OAAO,MAAM;AACvB,OAAI,QAAQ,SAAU;AAEtB,OAAI,KAAK,qBAAqB,IAAI,EAAE;IACnC,MAAM,QAAS,KAAa;AAE5B,QAAI;AACH,UAAK,UAAU,MAAM;AACrB,SAAI,OAAO;aACH,OAAO;AACf,SAAI,OAAO,OAAO,MAAM;;;;AAK3B,SAAO;;CAGR,UAAmB;AAClB,MAAI;AACH,eAAY,KAAK,QAAQ,KAAK,OAAO,CAAC;AACtC,UAAO;UACA;AACP,UAAO;;;CAIT,iBAAiB,UAAyC;EACzD,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,UAA0B,EAAE;AAElC,OAAK,MAAM,OAAO,QACjB,KAAI,EAAE,OAAO,aAAa,QAAQ,SAAU,SAAiB,KAC5D,SAAQ,KAAK,IAAkB;AAIjC,SAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/schema/index.ts"],"sourcesContent":["import { TableKeys } from \"../types\"\n\nexport class Schema<T> {\n\tpublic readonly table_name: string\n\tpublic readonly clustering_order: any\n\tpublic readonly keys: TableKeys\n\tpublic readonly fields: T\n\n\tconstructor(params: any, fields: T) {\n\t\tthis.table_name = params.table_name\n\t\tthis.keys = params.keys\n\t\tthis.fields = fields\n\t}\n}\n\nexport default Schema\n"],"mappings":";AAEA,IAAa,SAAb,MAAuB;CACtB;CACA;CACA;CACA;CAEA,YAAY,QAAa,QAAW;AACnC,OAAK,aAAa,OAAO;AACzB,OAAK,OAAO,OAAO;AACnB,OAAK,SAAS"}
package/types.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import Result from \"./result\"\nimport { Schema } from \"./schema\"\n\nexport type ClientConfig = {\n\tmodelsPath?: string\n\tcontactPoints?: string[]\n\tlocalDataCenter?: string\n\tkeyspace?: string\n\tport?: number\n\tmaxRetries?: number\n\tretryDelay?: number\n\tpooling?: {\n\t\tcoreConnectionsPerHost?: Record<string, number>\n\t\tmaxRequestsPerConnection?: number\n\t}\n}\n\nexport enum ColumnTypes {\n\tAscii = \"ascii\",\n\tBigint = \"bigint\",\n\tBlob = \"blob\",\n\tBoolean = \"boolean\",\n\tCounter = \"counter\",\n\tDate = \"date\",\n\tDecimal = \"decimal\",\n\tDouble = \"double\",\n\tDuration = \"duration\",\n\tFloat = \"float\",\n\tFrozen = \"frozen\",\n\tInet = \"inet\",\n\tInt = \"int\",\n\tList = \"list\",\n\tMap = \"map\",\n\tSet = \"set\",\n\tSmallint = \"smallint\",\n\tText = \"text\",\n\tTime = \"time\",\n\tTimestamp = \"timestamp\",\n\tTimeuuid = \"timeuuid\",\n\tTinyint = \"tinyint\",\n\tTuple = \"tuple\",\n\tUuid = \"uuid\",\n\tVarchar = \"varchar\",\n\tVarint = \"varint\",\n}\n\nexport type QueryOperators<TValue> = {\n\t$eq?: TValue\n\t$ne?: TValue\n\t$in?: TValue[]\n\t$gt?: TValue\n\t$gte?: TValue\n\t$lt?: TValue\n\t$lte?: TValue\n}\n\nexport type TableKeys = (string | TableKeys)[]\n\nexport interface Column<T> {\n\ttype?: ColumnTypes | string\n\trequired?: boolean\n}\n\nexport type InferRawData<T> = {\n\t[K in keyof T as K extends `$${string}` ? never : K]: T[K] extends Column<\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: T[K]\n}\n\nexport type InferDocument<S> =\n\tS extends Schema<infer T> ? InferRawData<T> : never\n\n// export type DocOf<M extends Model<any>> =\n// \tM extends Model<infer S> ? InferDocument<S> : never\n\nexport type DocumentResult<TDoc> = Result<TDoc> & TDoc\n\nexport type QueryOptions = {\n\traw?: boolean\n}\n\nexport type OrderBy<TDoc> = { [K in keyof TDoc]?: \"asc\" | \"desc\" }\n\nexport type Query<TDoc> = {\n\t[K in keyof TDoc]?: TDoc[K] | QueryOperators<TDoc[K]>\n} & {\n\t$and?: Query<TDoc>[]\n\t$limit?: number\n\t$orderby?: OrderBy<TDoc>\n}\n"],"mappings":";AAiBA,IAAY,cAAL,yBAAA,aAAA;AACN,aAAA,WAAA;AACA,aAAA,YAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,aAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,YAAA;AACA,aAAA,cAAA;AACA,aAAA,WAAA;AACA,aAAA,YAAA;AACA,aAAA,UAAA;AACA,aAAA,SAAA;AACA,aAAA,UAAA;AACA,aAAA,SAAA;AACA,aAAA,SAAA;AACA,aAAA,cAAA;AACA,aAAA,UAAA;AACA,aAAA,UAAA;AACA,aAAA,eAAA;AACA,aAAA,cAAA;AACA,aAAA,aAAA;AACA,aAAA,WAAA;AACA,aAAA,UAAA;AACA,aAAA,aAAA;AACA,aAAA,YAAA;;KACA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildMapper.mjs","names":[],"sources":["../../src/utils/buildMapper.ts"],"sourcesContent":["export default (map) => {\n\treturn map.reduce((obj, { name, schema }) => {\n\t\treturn {\n\t\t\t...obj,\n\t\t\t[name]: {\n\t\t\t\ttables: [schema.table_name],\n\t\t\t},\n\t\t}\n\t}, {})\n}\n"],"mappings":";AAAA,IAAA,uBAAgB,QAAQ;AACvB,QAAO,IAAI,QAAQ,KAAK,EAAE,MAAM,aAAa;AAC5C,SAAO;GACN,GAAG;IACF,OAAO,EACP,QAAQ,CAAC,OAAO,WAAW,EAC3B;GACD;IACC,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fillDefaults.mjs","names":[],"sources":["../../src/utils/fillDefaults.ts"],"sourcesContent":["export default function fillDefaults(schema: any, data: any) {\n\tconst defaults = schema.options?.defaults\n\n\tif (!defaults || Object.keys(defaults).length === 0) {\n\t\treturn data\n\t}\n\n\tlet needsDefaults = false\n\n\tfor (const key in defaults) {\n\t\tif (data[key] == null) {\n\t\t\tneedsDefaults = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (!needsDefaults) {\n\t\treturn data\n\t}\n\n\tconst result = Object.assign({}, data)\n\n\tfor (const key in defaults) {\n\t\tif (result[key] == null) {\n\t\t\tresult[key] = defaults[key]\n\t\t}\n\t}\n\n\treturn result\n}\n"],"mappings":";AAAA,SAAwB,aAAa,QAAa,MAAW;CAC5D,MAAM,WAAW,OAAO,SAAS;AAEjC,KAAI,CAAC,YAAY,OAAO,KAAK,SAAS,CAAC,WAAW,EACjD,QAAO;CAGR,IAAI,gBAAgB;AAEpB,MAAK,MAAM,OAAO,SACjB,KAAI,KAAK,QAAQ,MAAM;AACtB,kBAAgB;AAChB;;AAIF,KAAI,CAAC,cACJ,QAAO;CAGR,MAAM,SAAS,OAAO,OAAO,EAAE,EAAE,KAAK;AAEtC,MAAK,MAAM,OAAO,SACjB,KAAI,OAAO,QAAQ,KAClB,QAAO,OAAO,SAAS;AAIzB,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadModels.mjs","names":[],"sources":["../../src/utils/loadModels.ts"],"sourcesContent":["import fs from \"node:fs\"\nimport path from \"node:path\"\n\nexport default async (fromPath: string): Promise<any[]> => {\n\tif (typeof fromPath !== \"string\") {\n\t\treturn []\n\t}\n\n\tif (!fs.existsSync(fromPath)) {\n\t\tconsole.warn(\n\t\t\t`Cannot load models from [${fromPath}] case this path does not exist`,\n\t\t)\n\t\treturn []\n\t}\n\n\tlet mods = []\n\n\tlet files = await fs.promises.readdir(fromPath)\n\n\tfiles = files.filter((file) => file.endsWith(\".js\") || file.endsWith(\".ts\"))\n\n\tfor await (const file of files) {\n\t\tconst name = file.replace(\".js\", \"\")\n\t\tconst file_path = path.join(fromPath, file)\n\n\t\ttry {\n\t\t\tlet mod = await import(file_path)\n\n\t\t\tmod = mod.default\n\n\t\t\tmods.push(mod)\n\t\t} catch (error) {\n\t\t\tconsole.error(`Failed to load model [${name}]:`, error)\n\t\t\tcontinue\n\t\t}\n\t}\n\n\treturn mods\n}\n"],"mappings":";;;AAGA,IAAA,qBAAe,OAAO,aAAqC;AAC1D,KAAI,OAAO,aAAa,SACvB,QAAO,EAAE;AAGV,KAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC7B,UAAQ,KACP,4BAA4B,SAAS,iCACrC;AACD,SAAO,EAAE;;CAGV,IAAI,OAAO,EAAE;CAEb,IAAI,QAAQ,MAAM,GAAG,SAAS,QAAQ,SAAS;AAE/C,SAAQ,MAAM,QAAQ,SAAS,KAAK,SAAS,MAAM,IAAI,KAAK,SAAS,MAAM,CAAC;AAE5E,YAAW,MAAM,QAAQ,OAAO;EAC/B,MAAM,OAAO,KAAK,QAAQ,OAAO,GAAG;EACpC,MAAM,YAAY,KAAK,KAAK,UAAU,KAAK;AAE3C,MAAI;GACH,IAAI,MAAM,MAAM,OAAO;AAEvB,SAAM,IAAI;AAEV,QAAK,KAAK,IAAI;WACN,OAAO;AACf,WAAQ,MAAM,yBAAyB,KAAK,KAAK,MAAM;AACvD;;;AAIF,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"queryParser.mjs","names":["cassandra"],"sources":["../../src/utils/queryParser.ts"],"sourcesContent":["import type { Model } from \"../model\"\n\n// @ts-ignore\nimport cassandra from \"cassandra-driver\"\nconst { q } = cassandra.mapping\n\nconst MAX_QUERY_DEPTH = 3\nconst MAX_IN_ELEMENTS = 1000\n\nconst VALID_OPERATORS = new Set([\n\t\"$eq\",\n\t\"$ne\",\n\t\"$gt\",\n\t\"$gte\",\n\t\"$lt\",\n\t\"$lte\",\n\t\"$in\",\n])\n\nfunction requireNotNull(value: any, operator: string): void {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(\n\t\t\t`${operator} operator cannot compare with null or undefined`,\n\t\t)\n\t}\n}\n\nfunction buildOperator(operator: string, opValue: any): any {\n\tif (!VALID_OPERATORS.has(operator)) {\n\t\tthrow new Error(`Invalid operator: ${operator}`)\n\t}\n\n\tswitch (operator) {\n\t\tcase \"$eq\":\n\t\t\treturn opValue\n\n\t\tcase \"$ne\":\n\t\t\trequireNotNull(opValue, \"$ne\")\n\t\t\treturn q.notEq(opValue)\n\n\t\tcase \"$in\":\n\t\t\tif (!Array.isArray(opValue)) {\n\t\t\t\tthrow new Error(\"$in operator requires an array\")\n\t\t\t}\n\t\t\tif (opValue.length > MAX_IN_ELEMENTS) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`$in operator exceeds maximum of ${MAX_IN_ELEMENTS} elements`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (let i = 0; i < opValue.length; i++) {\n\t\t\t\tif (opValue[i] === null || opValue[i] === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`$in array element at index ${i} cannot be null or undefined`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn q.in_(opValue)\n\n\t\tcase \"$gt\":\n\t\t\trequireNotNull(opValue, \"$gt\")\n\t\t\treturn q.gt(opValue)\n\n\t\tcase \"$gte\":\n\t\t\trequireNotNull(opValue, \"$gte\")\n\t\t\treturn q.gte(opValue)\n\n\t\tcase \"$lt\":\n\t\t\trequireNotNull(opValue, \"$lt\")\n\t\t\treturn q.lt(opValue)\n\n\t\tcase \"$lte\":\n\t\t\trequireNotNull(opValue, \"$lte\")\n\t\t\treturn q.lte(opValue)\n\t}\n}\n\nexport default function queryParser(\n\tmodel: Model<any>,\n\tquery: any,\n\tdepth: number = 0,\n) {\n\tif (depth > MAX_QUERY_DEPTH) {\n\t\tthrow new Error(`Query depth exceeds maximum of ${MAX_QUERY_DEPTH}`)\n\t}\n\n\tif (!query || typeof query !== \"object\") {\n\t\treturn query\n\t}\n\n\tconst parsedQuery: Record<string, any> = {}\n\tconst fields = model.schema.fields\n\n\tfor (const field of Object.keys(query)) {\n\t\tconst value = query[field]\n\n\t\tif (field === \"$and\") {\n\t\t\thandleAnd(model, value, parsedQuery, depth)\n\t\t\tcontinue\n\t\t}\n\n\t\tif (field === \"$or\") {\n\t\t\tthrow new Error(\n\t\t\t\t\"ScyllaDB does not support OR queries across different columns. Use $in for a single column.\",\n\t\t\t)\n\t\t}\n\n\t\tif (!isValidFieldName(fields, field)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid field name: [${field}] or it does not exist in schema`,\n\t\t\t)\n\t\t}\n\n\t\tparsedQuery[field] = parseField(value)\n\t}\n\n\treturn parsedQuery\n}\n\nfunction handleAnd(\n\tmodel: Model<any>,\n\tconditions: any,\n\tparsedQuery: Record<string, any>,\n\tdepth: number,\n) {\n\tif (!Array.isArray(conditions)) {\n\t\tthrow new Error(\"$and operator requires an array\")\n\t}\n\tif (conditions.length > 10) {\n\t\tthrow new Error(\"$and operator exceeds maximum of 10 conditions\")\n\t}\n\n\tfor (let i = 0; i < conditions.length; i++) {\n\t\tconst condition = conditions[i]\n\t\tif (!condition || typeof condition !== \"object\") {\n\t\t\tthrow new Error(`$and condition at index ${i} must be an object`)\n\t\t}\n\n\t\tconst parsed = queryParser(model, condition, depth + 1)\n\t\tfor (const key of Object.keys(parsed)) {\n\t\t\tif (key in parsedQuery) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`$and conflict: field \"${key}\" appears in multiple conditions`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tObject.assign(parsedQuery, parsed)\n\t}\n}\n\nfunction parseField(value: any): any {\n\tif (\n\t\tvalue === null ||\n\t\ttypeof value !== \"object\" ||\n\t\tArray.isArray(value) ||\n\t\tvalue instanceof Date\n\t) {\n\t\tif (Array.isArray(value)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Array values require explicit operator (e.g., $in)\",\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n\n\tconst operators = Object.keys(value)\n\tconst compiledOps = operators.map((op) => buildOperator(op, value[op]))\n\n\treturn compiledOps.length === 1\n\t\t? compiledOps[0]\n\t\t: (q.and as any)(...compiledOps)\n}\n\nexport function isValidFieldName(\n\tfields: Record<string, any>,\n\tfieldName: string,\n): boolean {\n\tconst invalidPatterns = [\n\t\t/^[0-9]/,\n\t\t/[^a-zA-Z0-9_]/,\n\t\t/^(select|insert|update|delete|drop|create|alter|truncate)$/i,\n\t]\n\n\tfor (const pattern of invalidPatterns) {\n\t\tif (pattern.test(fieldName)) return false\n\t}\n\n\treturn fieldName in fields\n}\n\nexport function isValidOperator(operator: string): boolean {\n\treturn VALID_OPERATORS.has(operator)\n}\n"],"mappings":";;AAIA,MAAM,EAAE,MAAMA,UAAU;AAExB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,MAAM,kBAAkB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,SAAS,eAAe,OAAY,UAAwB;AAC3D,KAAI,UAAU,QAAQ,UAAU,KAAA,EAC/B,OAAM,IAAI,MACT,GAAG,SAAS,iDACZ;;AAIH,SAAS,cAAc,UAAkB,SAAmB;AAC3D,KAAI,CAAC,gBAAgB,IAAI,SAAS,CACjC,OAAM,IAAI,MAAM,qBAAqB,WAAW;AAGjD,SAAQ,UAAR;EACC,KAAK,MACJ,QAAO;EAER,KAAK;AACJ,kBAAe,SAAS,MAAM;AAC9B,UAAO,EAAE,MAAM,QAAQ;EAExB,KAAK;AACJ,OAAI,CAAC,MAAM,QAAQ,QAAQ,CAC1B,OAAM,IAAI,MAAM,iCAAiC;AAElD,OAAI,QAAQ,SAAS,gBACpB,OAAM,IAAI,MACT,mCAAmC,gBAAgB,WACnD;AAEF,QAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,IACnC,KAAI,QAAQ,OAAO,QAAQ,QAAQ,OAAO,KAAA,EACzC,OAAM,IAAI,MACT,8BAA8B,EAAE,8BAChC;AAGH,UAAO,EAAE,IAAI,QAAQ;EAEtB,KAAK;AACJ,kBAAe,SAAS,MAAM;AAC9B,UAAO,EAAE,GAAG,QAAQ;EAErB,KAAK;AACJ,kBAAe,SAAS,OAAO;AAC/B,UAAO,EAAE,IAAI,QAAQ;EAE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ACV,OAAO,UAAU,YACjB,MAAM,QAAQ,MAAM,IACpB,iBAAiB,MAChB;AACD,MAAI,MAAM,QAAQ,MAAM,CACvB,OAAM,IAAI,MACT,qDACA;AAEF,SAAO;;CAIR,MAAM,cADY,OAAO,KAAK,MACD,CAAC,KAAK,OAAO,cAAc,IAAI,MAAM,IAAI,CAAC;AAEvE,QAAO,YAAY,WAAW,IAC3B,YAAY,KACX,EAAE,IAAY,GAAG,YAAY;;AAGlC,SAAgB,iBACf,QACA,WACU;AAOV,MAAK,MAAM,WAAW;EALrB;EACA;EACA;EAGoC,CACpC,KAAI,QAAQ,KAAK,UAAU,CAAE,QAAO;AAGrC,QAAO,aAAa;;AAGrB,SAAgB,gBAAgB,UAA2B;AAC1D,QAAO,gBAAgB,IAAI,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeChecker.mjs","names":["cassandra"],"sources":["../../src/utils/typeChecker.ts"],"sourcesContent":["// @ts-ignore\nimport cassandra from \"cassandra-driver\"\nconst { types } = cassandra\nimport type { Model } from \"../model\"\nimport { isValidFieldName } from \"./queryParser\"\n\nconst stringTypes = new Set([\"ascii\", \"text\", \"varchar\", \"inet\"])\nconst intTypes = new Set([\"int\", \"smallint\", \"tinyint\"])\nconst floatTypes = new Set([\"double\", \"float\"])\nconst longTypes = new Set([\"bigint\", \"counter\"])\n\nfunction isValidValue(value: any, expectedType: string): boolean {\n\tif (value === null || value === undefined) return true\n\n\tif (stringTypes.has(expectedType)) return typeof value === \"string\"\n\tif (intTypes.has(expectedType)) return Number.isInteger(value)\n\tif (floatTypes.has(expectedType)) return typeof value === \"number\"\n\tif (longTypes.has(expectedType)) {\n\t\treturn (\n\t\t\ttypeof value === \"bigint\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\tvalue instanceof types.Long\n\t\t)\n\t}\n\n\tswitch (expectedType) {\n\t\tcase \"boolean\":\n\t\t\treturn typeof value === \"boolean\"\n\t\tcase \"decimal\":\n\t\t\treturn (\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\ttypeof value === \"string\" ||\n\t\t\t\tvalue instanceof types.BigDecimal\n\t\t\t)\n\t\tcase \"varint\":\n\t\t\treturn (\n\t\t\t\ttypeof value === \"bigint\" ||\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\tvalue instanceof types.Integer\n\t\t\t)\n\t\tcase \"timestamp\":\n\t\t\treturn (\n\t\t\t\tvalue instanceof Date ||\n\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\ttypeof value === \"string\"\n\t\t\t)\n\t\tcase \"date\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.LocalDate\n\t\tcase \"time\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.LocalTime\n\t\tcase \"uuid\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.Uuid\n\t\tcase \"timeuuid\":\n\t\t\treturn typeof value === \"string\" || value instanceof types.TimeUuid\n\t\tcase \"blob\":\n\t\t\treturn Buffer.isBuffer(value) || value instanceof Uint8Array\n\t}\n\n\tif (expectedType.startsWith(\"list<\") || expectedType.startsWith(\"set<\")) {\n\t\treturn Array.isArray(value) || value instanceof Set\n\t}\n\tif (expectedType.startsWith(\"map<\")) {\n\t\treturn (\n\t\t\ttypeof value === \"object\" && !Array.isArray(value) && value !== null\n\t\t)\n\t}\n\n\treturn false\n}\n\nexport default function typeChecker(model: Model<any>, data: any): boolean {\n\tif (!data || typeof data !== \"object\" || Array.isArray(data)) {\n\t\tthrow new TypeError(\n\t\t\t`[${model.name}] Validation error: Data payload must be an object`,\n\t\t)\n\t}\n\n\tconst fields = model.schema.fields\n\n\tfor (const [key, value] of Object.entries(data)) {\n\t\tif (!isValidFieldName(fields, key)) {\n\t\t\tthrow new Error(\n\t\t\t\t`[${model.name}] Validation error: Field '${key}' does not exist in schema`,\n\t\t\t)\n\t\t}\n\n\t\tconst fieldConfig = fields[key]\n\t\tconst expectedType = (fieldConfig.type || \"text\").toLowerCase()\n\n\t\tif (!isValidValue(value, expectedType)) {\n\t\t\tconst receivedType = Array.isArray(value) ? \"array\" : typeof value\n\t\t\tthrow new TypeError(\n\t\t\t\t`[${model.name}] Validation error: Invalid type for field '${key}'. ` +\n\t\t\t\t\t`Expected[${expectedType}], but received [${receivedType}]`,\n\t\t\t)\n\t\t}\n\t}\n\n\treturn true\n}\n"],"mappings":";;;AAEA,MAAM,EAAE,UAAUA;AAIlB,MAAM,cAAc,IAAI,IAAI;CAAC;CAAS;CAAQ;CAAW;CAAO,CAAC;AACjE,MAAM,WAAW,IAAI,IAAI;CAAC;CAAO;CAAY;CAAU,CAAC;AACxD,MAAM,aAAa,IAAI,IAAI,CAAC,UAAU,QAAQ,CAAC;AAC/C,MAAM,YAAY,IAAI,IAAI,CAAC,UAAU,UAAU,CAAC;AAEhD,SAAS,aAAa,OAAY,cAA+B;AAChE,KAAI,UAAU,QAAQ,UAAU,KAAA,EAAW,QAAO;AAElD,KAAI,YAAY,IAAI,aAAa,CAAE,QAAO,OAAO,UAAU;AAC3D,KAAI,SAAS,IAAI,aAAa,CAAE,QAAO,OAAO,UAAU,MAAM;AAC9D,KAAI,WAAW,IAAI,aAAa,CAAE,QAAO,OAAO,UAAU;AAC1D,KAAI,UAAU,IAAI,aAAa,CAC9B,QACC,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,iBAAiB,MAAM;AAIzB,SAAQ,cAAR;EACC,KAAK,UACJ,QAAO,OAAO,UAAU;EACzB,KAAK,UACJ,QACC,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,iBAAiB,MAAM;EAEzB,KAAK,SACJ,QACC,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,iBAAiB,MAAM;EAEzB,KAAK,YACJ,QACC,iBAAiB,QACjB,OAAO,UAAU,YACjB,OAAO,UAAU;EAEnB,KAAK,OACJ,QAAO,OAAO,UAAU,YAAY,iBAAiB,MAAM;EAC5D,KAAK,OACJ,QAAO,OAAO,UAAU,YAAY,iBAAiB,MAAM;EAC5D,KAAK,OACJ,QAA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