@rushdb/javascript-sdk 0.9.4 → 0.9.5

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 (100) hide show
  1. package/dist/index.cjs +1 -0
  2. package/dist/index.mjs +1 -0
  3. package/dist/index.node.d.ts +137 -0
  4. package/dist/index.worker.d.ts +137 -0
  5. package/{types → dist}/sdk/model.d.ts +4 -4
  6. package/{types → dist}/sdk/record.d.ts +3 -3
  7. package/{types → dist}/sdk/sdk.d.ts +24 -24
  8. package/{types → dist}/sdk/transaction.d.ts +2 -2
  9. package/{types → dist}/types/query.d.ts +1 -2
  10. package/package.json +10 -34
  11. package/CHANGELOG.md +0 -180
  12. package/cjs/api/api.js +0 -328
  13. package/cjs/api/constants.js +0 -7
  14. package/cjs/api/create-api.js +0 -323
  15. package/cjs/api/index.js +0 -8
  16. package/cjs/api/rest-api-proxy.js +0 -22
  17. package/cjs/api/types.js +0 -2
  18. package/cjs/api/utils.js +0 -155
  19. package/cjs/common/constants.js +0 -10
  20. package/cjs/common/utils.js +0 -46
  21. package/cjs/index.cjs.node.js +0 -24
  22. package/cjs/index.cjs.worker.js +0 -24
  23. package/cjs/network/FetchHttpClient.js +0 -138
  24. package/cjs/network/HttpClient.js +0 -59
  25. package/cjs/network/NodeHttpClient.js +0 -103
  26. package/cjs/network/index.js +0 -28
  27. package/cjs/network/types.js +0 -2
  28. package/cjs/package.json +0 -4
  29. package/cjs/sdk/constants.js +0 -13
  30. package/cjs/sdk/errors.js +0 -27
  31. package/cjs/sdk/index.js +0 -23
  32. package/cjs/sdk/model.js +0 -147
  33. package/cjs/sdk/record.js +0 -122
  34. package/cjs/sdk/sdk.js +0 -46
  35. package/cjs/sdk/transaction.js +0 -17
  36. package/cjs/sdk/types.js +0 -2
  37. package/cjs/sdk/utils.js +0 -103
  38. package/cjs/types/expressions.js +0 -2
  39. package/cjs/types/index.js +0 -21
  40. package/cjs/types/query.js +0 -2
  41. package/cjs/types/schema.js +0 -2
  42. package/cjs/types/utils.js +0 -2
  43. package/cjs/types/value.js +0 -2
  44. package/esm/api/api.js +0 -324
  45. package/esm/api/constants.js +0 -4
  46. package/esm/api/create-api.js +0 -319
  47. package/esm/api/index.js +0 -2
  48. package/esm/api/rest-api-proxy.js +0 -18
  49. package/esm/api/types.js +0 -1
  50. package/esm/api/utils.js +0 -139
  51. package/esm/common/constants.js +0 -7
  52. package/esm/common/utils.js +0 -37
  53. package/esm/index.esm.node.js +0 -6
  54. package/esm/index.esm.worker.js +0 -6
  55. package/esm/network/FetchHttpClient.js +0 -133
  56. package/esm/network/HttpClient.js +0 -53
  57. package/esm/network/NodeHttpClient.js +0 -98
  58. package/esm/network/index.js +0 -24
  59. package/esm/network/types.js +0 -1
  60. package/esm/package.json +0 -4
  61. package/esm/sdk/constants.js +0 -10
  62. package/esm/sdk/errors.js +0 -21
  63. package/esm/sdk/index.js +0 -7
  64. package/esm/sdk/model.js +0 -143
  65. package/esm/sdk/record.js +0 -115
  66. package/esm/sdk/sdk.js +0 -42
  67. package/esm/sdk/transaction.js +0 -13
  68. package/esm/sdk/types.js +0 -1
  69. package/esm/sdk/utils.js +0 -93
  70. package/esm/types/expressions.js +0 -1
  71. package/esm/types/index.js +0 -5
  72. package/esm/types/query.js +0 -1
  73. package/esm/types/schema.js +0 -1
  74. package/esm/types/utils.js +0 -1
  75. package/esm/types/value.js +0 -1
  76. package/types/index.d.ts +0 -60
  77. /package/{types → dist}/api/api.d.ts +0 -0
  78. /package/{types → dist}/api/constants.d.ts +0 -0
  79. /package/{types → dist}/api/create-api.d.ts +0 -0
  80. /package/{types → dist}/api/index.d.ts +0 -0
  81. /package/{types → dist}/api/rest-api-proxy.d.ts +0 -0
  82. /package/{types → dist}/api/types.d.ts +0 -0
  83. /package/{types → dist}/api/utils.d.ts +0 -0
  84. /package/{types → dist}/common/constants.d.ts +0 -0
  85. /package/{types → dist}/common/utils.d.ts +0 -0
  86. /package/{types → dist}/network/FetchHttpClient.d.ts +0 -0
  87. /package/{types → dist}/network/HttpClient.d.ts +0 -0
  88. /package/{types → dist}/network/NodeHttpClient.d.ts +0 -0
  89. /package/{types → dist}/network/index.d.ts +0 -0
  90. /package/{types → dist}/network/types.d.ts +0 -0
  91. /package/{types → dist}/sdk/constants.d.ts +0 -0
  92. /package/{types → dist}/sdk/errors.d.ts +0 -0
  93. /package/{types → dist}/sdk/index.d.ts +0 -0
  94. /package/{types → dist}/sdk/types.d.ts +0 -0
  95. /package/{types → dist}/sdk/utils.d.ts +0 -0
  96. /package/{types → dist}/types/expressions.d.ts +0 -0
  97. /package/{types → dist}/types/index.d.ts +0 -0
  98. /package/{types → dist}/types/schema.d.ts +0 -0
  99. /package/{types → dist}/types/utils.d.ts +0 -0
  100. /package/{types → dist}/types/value.d.ts +0 -0
package/esm/sdk/utils.js DELETED
@@ -1,93 +0,0 @@
1
- import { isObject } from '../common/utils.js';
2
- import { ALLOWED_CONFIG_PROPERTIES } from './constants.js';
3
- import { UniquenessError } from './errors.js';
4
- export const mergeDefaultsWithPayload = async (schema, payload) => {
5
- const defaultPromises = Object.entries(schema).map(async ([key, prop]) => {
6
- if (prop.default &&
7
- typeof prop.default !== 'undefined' &&
8
- typeof payload[key] === 'undefined') {
9
- return {
10
- key,
11
- value: typeof prop.default === 'function' ? await prop.default() : prop.default
12
- };
13
- }
14
- else {
15
- return { key, value: undefined };
16
- }
17
- });
18
- const resolvedDefaults = await Promise.all(defaultPromises);
19
- const defaults = resolvedDefaults.reduce((acc, { key, value }) => {
20
- if (value !== undefined) {
21
- acc[key] = value;
22
- }
23
- return acc;
24
- }, {});
25
- return Object.assign(Object.assign({}, defaults), payload);
26
- };
27
- export const pickUniqFieldsFromRecord = (schema, data) => {
28
- return Object.entries(data)
29
- .filter(([key]) => { var _a; return (_a = schema[key]) === null || _a === void 0 ? void 0 : _a.uniq; })
30
- .reduce((acc, [key, value]) => {
31
- if (key in schema) {
32
- acc[key] = value;
33
- }
34
- return acc;
35
- }, {});
36
- };
37
- export const pickUniqFieldsFromRecords = (data, schema, label) => {
38
- const properties = {};
39
- const uniqFields = Object.entries(schema)
40
- .filter(([_, config]) => config.uniq)
41
- .reduce((acc, [key]) => {
42
- acc[key] = true;
43
- return acc;
44
- }, {});
45
- data.forEach((record) => {
46
- Object.entries(record).forEach(([key, value]) => {
47
- if (key in uniqFields) {
48
- if (properties[key]) {
49
- if (properties[key].includes(value)) {
50
- throw new UniquenessError(label, { [key]: value });
51
- }
52
- properties[key] = [...properties[key], value];
53
- }
54
- else {
55
- properties[key] = [value];
56
- }
57
- }
58
- });
59
- });
60
- return properties;
61
- };
62
- export const parseConfig = (config) => {
63
- if (!config) {
64
- return {};
65
- }
66
- if (!isObject(config)) {
67
- throw new Error('Config must be an object');
68
- }
69
- const values = Object.keys(config).filter((value) => !ALLOWED_CONFIG_PROPERTIES.includes(value));
70
- if (values.length > 0) {
71
- throw new Error(`Config object may only contain the following: ${ALLOWED_CONFIG_PROPERTIES.join(', ')}`);
72
- }
73
- return config;
74
- };
75
- export function validateInteger(name, n, defaultVal) {
76
- if (!Number.isInteger(n)) {
77
- if (defaultVal !== undefined) {
78
- return defaultVal;
79
- }
80
- else {
81
- throw new Error(`${name} must be an integer`);
82
- }
83
- }
84
- return n;
85
- }
86
- export function idToTimestamp(id) {
87
- const parts = id.split('-');
88
- const highBitsHex = parts[0] + parts[1].slice(0, 4);
89
- return parseInt(highBitsHex, 16);
90
- }
91
- export function idToDate(id) {
92
- return new Date(idToTimestamp(id));
93
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export * from './value.js';
2
- export * from './query.js';
3
- export * from './utils.js';
4
- export * from './schema.js';
5
- export * from './expressions.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/types/index.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import type { InferType, DBRecord, UserProvidedConfig, Relation } from './sdk'
2
-
3
- import { DBRecordsBatchDraft, DBRecordDraft, RestAPI, ApiResponse } from './api'
4
- import { HttpClient, HttpClientResponse } from './network/HttpClient'
5
- import {
6
- Model,
7
- DBRecordInstance,
8
- DBRecordsArrayInstance,
9
- Transaction,
10
- idToDate,
11
- idToTimestamp,
12
- EmptyTargetError,
13
- UniquenessError,
14
- NonUniqueResultError
15
- } from './sdk'
16
- import { Models, Schema } from './types'
17
-
18
- declare module '@rushdb/javascript-sdk' {
19
- export namespace RushDB {}
20
-
21
- export class RushDB extends RestAPI {
22
- static RushDB: typeof RushDB
23
-
24
- constructor(token?: string, config?: UserProvidedConfig)
25
- public api: RestAPI
26
-
27
- public registerModel<Model extends Model = Model>(model: Model): Model //Model<T['schema']>
28
- public getModel(label: string): Model
29
- public getModels(): Map<string, Model>
30
- public getInstance(token: string, config?: UserProvidedConfig): RushDB
31
- public toInstance<Schema extends Schema = Schema>(record: DBRecord<Schema>): DBRecordInstance
32
- }
33
-
34
- export {
35
- DBRecordsBatchDraft,
36
- Relation,
37
- ApiResponse,
38
- InferType,
39
- Model,
40
- Models,
41
- DBRecord,
42
- DBRecordDraft,
43
- DBRecordInstance,
44
- DBRecordsArrayInstance,
45
- RestAPI,
46
- Schema,
47
- Transaction,
48
- HttpClient,
49
- HttpClientResponse,
50
- EmptyTargetError,
51
- NonUniqueResultError,
52
- UniquenessError,
53
- idToDate,
54
- idToTimestamp
55
- }
56
-
57
- export * from './types'
58
-
59
- export default RushDB
60
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes