corebasic 1.0.211 → 1.0.213

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 (167) hide show
  1. package/dist/index.js +10 -0
  2. package/dist/libs/ObjectId.js +114 -0
  3. package/dist/libs/auth.js +103 -0
  4. package/dist/libs/compression.js +11 -0
  5. package/dist/libs/cpp.js +154 -0
  6. package/dist/libs/dip/suffix/date.js +89 -0
  7. package/dist/libs/dip/suffix/index.js +227 -0
  8. package/dist/libs/dip/suffix/policy.js +113 -0
  9. package/dist/libs/dip/suffix/query.js +279 -0
  10. package/dist/libs/dip/suffix/suffix.js +99 -0
  11. package/dist/libs/dip/suffix/tests/date.test.js +187 -0
  12. package/dist/libs/dip/suffix/tests/index.test.js +441 -0
  13. package/dist/libs/dip/suffix/tests/policy.applySuffixPolicy.test.js +489 -0
  14. package/dist/libs/dip/suffix/tests/policy.test.js +329 -0
  15. package/dist/libs/dip/suffix/tests/suffix.test.js +316 -0
  16. package/dist/libs/dip.js +102 -0
  17. package/dist/libs/dipper.js +73 -0
  18. package/dist/libs/elabase.js +656 -0
  19. package/dist/libs/features.js +366 -0
  20. package/dist/libs/kafka.js +121 -0
  21. package/dist/libs/messaging.js +130 -0
  22. package/dist/libs/mobilecodes.js +562 -0
  23. package/dist/libs/session.js +96 -0
  24. package/dist/libs/utils.js +297 -0
  25. package/index.ts +23 -0
  26. package/libs/{auth.js → auth.ts} +3 -3
  27. package/libs/{compression.js → compression.ts} +1 -1
  28. package/libs/dip/suffix/date.ts +121 -0
  29. package/libs/dip/suffix/{index.js → index.ts} +7 -18
  30. package/libs/dip/suffix/{policy.js → policy.ts} +2 -2
  31. package/libs/dip/suffix/{suffix.js → suffix.ts} +2 -2
  32. package/libs/dip/suffix/tests/{date.test.js → date.test.ts} +1 -1
  33. package/libs/dip/suffix/tests/{index.test.js → index.test.ts} +1 -1
  34. package/libs/dip/suffix/tests/{policy.applySuffixPolicy.test.js → policy.applySuffixPolicy.test.ts} +1 -1
  35. package/libs/dip/suffix/tests/{policy.test.js → policy.test.ts} +1 -1
  36. package/libs/dip/suffix/tests/{suffix.test.js → suffix.test.ts} +1 -1
  37. package/libs/{dip.js → dip.ts} +1 -1
  38. package/libs/{elabase.js → elabase.ts} +4 -4
  39. package/libs/{features.js → features.ts} +5 -5
  40. package/libs/{messaging.js → messaging.ts} +1 -1
  41. package/libs/{session.js → session.ts} +2 -2
  42. package/libs/{utils.js → utils.ts} +80 -9
  43. package/package.json +3 -2
  44. package/tsc/@typescript/typescript-linux-x64/LICENSE +55 -0
  45. package/tsc/@typescript/typescript-linux-x64/NOTICE.txt +436 -0
  46. package/tsc/@typescript/typescript-linux-x64/README.md +3 -0
  47. package/tsc/@typescript/typescript-linux-x64/lib/lib.d.ts +20 -0
  48. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.d.ts +382 -0
  49. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.legacy.d.ts +20 -0
  50. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.asynciterable.d.ts +18 -0
  51. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.d.ts +45125 -0
  52. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.iterable.d.ts +18 -0
  53. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.collection.d.ts +159 -0
  54. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.core.d.ts +595 -0
  55. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.d.ts +26 -0
  56. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.generator.d.ts +75 -0
  57. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.iterable.d.ts +603 -0
  58. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.promise.d.ts +79 -0
  59. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.proxy.d.ts +126 -0
  60. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.reflect.d.ts +142 -0
  61. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.d.ts +44 -0
  62. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
  63. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.array.include.d.ts +114 -0
  64. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.d.ts +19 -0
  65. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.full.d.ts +21 -0
  66. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.intl.d.ts +29 -0
  67. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.arraybuffer.d.ts +19 -0
  68. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.d.ts +24 -0
  69. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.date.d.ts +29 -0
  70. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.full.d.ts +21 -0
  71. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.intl.d.ts +42 -0
  72. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.object.d.ts +47 -0
  73. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.sharedmemory.d.ts +133 -0
  74. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.string.d.ts +47 -0
  75. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.typedarrays.d.ts +51 -0
  76. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asyncgenerator.d.ts +75 -0
  77. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asynciterable.d.ts +51 -0
  78. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.d.ts +22 -0
  79. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.full.d.ts +22 -0
  80. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.intl.d.ts +81 -0
  81. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.promise.d.ts +28 -0
  82. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.regexp.d.ts +35 -0
  83. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.array.d.ts +77 -0
  84. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.d.ts +22 -0
  85. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.full.d.ts +22 -0
  86. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.intl.d.ts +21 -0
  87. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.object.d.ts +31 -0
  88. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.string.d.ts +35 -0
  89. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.symbol.d.ts +22 -0
  90. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.bigint.d.ts +763 -0
  91. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.d.ts +25 -0
  92. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.date.d.ts +40 -0
  93. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.full.d.ts +22 -0
  94. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.intl.d.ts +472 -0
  95. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.number.d.ts +26 -0
  96. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.promise.d.ts +45 -0
  97. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.sharedmemory.d.ts +97 -0
  98. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.string.d.ts +42 -0
  99. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
  100. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.d.ts +21 -0
  101. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.full.d.ts +22 -0
  102. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.intl.d.ts +164 -0
  103. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.promise.d.ts +46 -0
  104. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.string.d.ts +31 -0
  105. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.weakref.d.ts +76 -0
  106. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.array.d.ts +119 -0
  107. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.d.ts +23 -0
  108. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.error.d.ts +73 -0
  109. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.full.d.ts +22 -0
  110. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.intl.d.ts +143 -0
  111. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.object.d.ts +24 -0
  112. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.regexp.d.ts +37 -0
  113. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.string.d.ts +23 -0
  114. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.array.d.ts +922 -0
  115. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.collection.d.ts +19 -0
  116. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.d.ts +20 -0
  117. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.full.d.ts +22 -0
  118. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.intl.d.ts +62 -0
  119. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.arraybuffer.d.ts +63 -0
  120. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.collection.d.ts +27 -0
  121. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.d.ts +24 -0
  122. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.full.d.ts +22 -0
  123. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.object.d.ts +27 -0
  124. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.promise.d.ts +33 -0
  125. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.regexp.d.ts +23 -0
  126. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.sharedmemory.d.ts +66 -0
  127. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.string.d.ts +27 -0
  128. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.collection.d.ts +94 -0
  129. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.d.ts +23 -0
  130. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.float16.d.ts +443 -0
  131. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.full.d.ts +22 -0
  132. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.intl.d.ts +200 -0
  133. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.iterator.d.ts +146 -0
  134. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.promise.d.ts +32 -0
  135. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.regexp.d.ts +30 -0
  136. package/tsc/@typescript/typescript-linux-x64/lib/lib.es5.d.ts +4599 -0
  137. package/tsc/@typescript/typescript-linux-x64/lib/lib.es6.d.ts +21 -0
  138. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.array.d.ts +33 -0
  139. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.collection.d.ts +47 -0
  140. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.d.ts +27 -0
  141. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.date.d.ts +21 -0
  142. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.decorators.d.ts +26 -0
  143. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.disposable.d.ts +191 -0
  144. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.error.d.ts +22 -0
  145. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.full.d.ts +22 -0
  146. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.intl.d.ts +107 -0
  147. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.sharedmemory.d.ts +23 -0
  148. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.temporal.d.ts +485 -0
  149. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.typedarrays.d.ts +90 -0
  150. package/tsc/@typescript/typescript-linux-x64/lib/lib.scripthost.d.ts +320 -0
  151. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.asynciterable.d.ts +18 -0
  152. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.d.ts +15606 -0
  153. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.importscripts.d.ts +21 -0
  154. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.iterable.d.ts +18 -0
  155. package/tsc/@typescript/typescript-linux-x64/lib/tsc +0 -0
  156. package/tsc/@typescript/typescript-linux-x64/lib/tsc.sig +11 -0
  157. package/tsc/@typescript/typescript-linux-x64/package.json +45 -0
  158. package/tsc/notes +14 -0
  159. package/tsconfig.json +48 -0
  160. package/index.js +0 -23
  161. package/libs/dip/suffix/date.js +0 -103
  162. /package/libs/{ObjectId.js → ObjectId.ts} +0 -0
  163. /package/libs/{cpp.js → cpp.ts} +0 -0
  164. /package/libs/dip/suffix/{query.js → query.ts} +0 -0
  165. /package/libs/{dipper.js → dipper.ts} +0 -0
  166. /package/libs/{kafka.js → kafka.ts} +0 -0
  167. /package/libs/{mobilecodes.js → mobilecodes.ts} +0 -0
@@ -0,0 +1,489 @@
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { applySuffixPolicy } from "../policy.js";
4
+ // -----------------------------------------------------------------------------
5
+ // applySuffixPolicy()
6
+ // -----------------------------------------------------------------------------
7
+ describe("applySuffixPolicy()", () => {
8
+ test("no collection", async () => {
9
+ const collections = {};
10
+ const result = await applySuffixPolicy(collections, "missing", {});
11
+ assert.deepEqual(result, []);
12
+ });
13
+ test("collection without policy", async () => {
14
+ const collections = {
15
+ invoices: {}
16
+ };
17
+ const result = await applySuffixPolicy(collections, "invoices", {});
18
+ assert.deepEqual(result, []);
19
+ });
20
+ test("empty policy array", async () => {
21
+ const collections = {
22
+ invoices: {
23
+ policy: []
24
+ }
25
+ };
26
+ const result = await applySuffixPolicy(collections, "invoices", {});
27
+ assert.deepEqual(result, []);
28
+ });
29
+ test("single policy object", async () => {
30
+ const collections = {
31
+ invoices: {
32
+ policy: {
33
+ suffix: [
34
+ { key: "type" }
35
+ ]
36
+ }
37
+ }
38
+ };
39
+ const result = await applySuffixPolicy(collections, "invoices", {
40
+ type: "Sales"
41
+ });
42
+ assert.deepEqual(result, [
43
+ "/Sales"
44
+ ]);
45
+ });
46
+ test("single policy array", async () => {
47
+ const collections = {
48
+ invoices: {
49
+ policy: [
50
+ {
51
+ suffix: [
52
+ { key: "type" }
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ };
58
+ const result = await applySuffixPolicy(collections, "invoices", {
59
+ type: "Sales"
60
+ });
61
+ assert.deepEqual(result, [
62
+ "/Sales"
63
+ ]);
64
+ });
65
+ test("unconditional policy", async () => {
66
+ const collections = {
67
+ invoices: {
68
+ policy: {
69
+ when: {},
70
+ suffix: [
71
+ { key: "type" }
72
+ ]
73
+ }
74
+ }
75
+ };
76
+ const result = await applySuffixPolicy(collections, "invoices", {
77
+ type: "Sales"
78
+ });
79
+ assert.deepEqual(result, [
80
+ "/Sales"
81
+ ]);
82
+ });
83
+ test("policy matches equality", async () => {
84
+ const collections = {
85
+ invoices: {
86
+ policy: {
87
+ when: {
88
+ status: "Active"
89
+ },
90
+ suffix: [
91
+ { key: "type" }
92
+ ]
93
+ }
94
+ }
95
+ };
96
+ const result = await applySuffixPolicy(collections, "invoices", {
97
+ status: "Active",
98
+ type: "Sales"
99
+ });
100
+ assert.deepEqual(result, [
101
+ "/Sales"
102
+ ]);
103
+ });
104
+ test("policy does not match equality", async () => {
105
+ const collections = {
106
+ invoices: {
107
+ policy: {
108
+ when: {
109
+ status: "Active"
110
+ },
111
+ suffix: [
112
+ { key: "type" }
113
+ ]
114
+ }
115
+ }
116
+ };
117
+ const result = await applySuffixPolicy(collections, "invoices", {
118
+ status: "Deleted",
119
+ type: "Sales"
120
+ });
121
+ assert.deepEqual(result, []);
122
+ });
123
+ test("$in subset", async () => {
124
+ const collections = {
125
+ invoices: {
126
+ policy: {
127
+ when: {
128
+ status: { $in: ["Active"] }
129
+ },
130
+ suffix: [
131
+ { key: "type" }
132
+ ]
133
+ }
134
+ }
135
+ };
136
+ const result = await applySuffixPolicy(collections, "invoices", {
137
+ status: { $in: ["Active", "Pending"] },
138
+ type: "Sales"
139
+ });
140
+ assert.deepEqual(result, [
141
+ "/Sales"
142
+ ]);
143
+ });
144
+ test("multiple matching policies", async () => {
145
+ const collections = {
146
+ invoices: {
147
+ policy: [
148
+ {
149
+ when: {
150
+ status: "Active"
151
+ },
152
+ suffix: [
153
+ { key: "type" }
154
+ ]
155
+ },
156
+ {
157
+ when: {
158
+ status: "Active"
159
+ },
160
+ suffix: [
161
+ { key: "region" }
162
+ ]
163
+ }
164
+ ]
165
+ }
166
+ };
167
+ const result = await applySuffixPolicy(collections, "invoices", {
168
+ status: "Active",
169
+ type: "Sales",
170
+ region: "IN"
171
+ });
172
+ assert.deepEqual(result.sort(), [
173
+ "/Sales",
174
+ "/IN"
175
+ ].sort());
176
+ });
177
+ test("one policy matches one skipped", async () => {
178
+ const collections = {
179
+ invoices: {
180
+ policy: [
181
+ {
182
+ when: {
183
+ status: "Active"
184
+ },
185
+ suffix: [
186
+ { key: "type" }
187
+ ]
188
+ },
189
+ {
190
+ when: {
191
+ status: "Deleted"
192
+ },
193
+ suffix: [
194
+ { key: "region" }
195
+ ]
196
+ }
197
+ ]
198
+ }
199
+ };
200
+ const result = await applySuffixPolicy(collections, "invoices", {
201
+ status: "Active",
202
+ type: "Sales",
203
+ region: "IN"
204
+ });
205
+ assert.deepEqual(result, [
206
+ "/Sales"
207
+ ]);
208
+ });
209
+ test("duplicate suffix removed", async () => {
210
+ const collections = {
211
+ invoices: {
212
+ policy: [
213
+ {
214
+ suffix: [
215
+ { key: "type" }
216
+ ]
217
+ },
218
+ {
219
+ suffix: [
220
+ { key: "type" }
221
+ ]
222
+ }
223
+ ]
224
+ }
225
+ };
226
+ const result = await applySuffixPolicy(collections, "invoices", {
227
+ type: "Sales"
228
+ });
229
+ assert.deepEqual(result, [
230
+ "/Sales"
231
+ ]);
232
+ });
233
+ test("date suffix", async () => {
234
+ const collections = {
235
+ invoices: {
236
+ policy: {
237
+ suffix: [
238
+ {
239
+ key: "date",
240
+ type: "date:YYYY"
241
+ }
242
+ ]
243
+ }
244
+ }
245
+ };
246
+ const result = await applySuffixPolicy(collections, "invoices", {
247
+ date: new Date(2026, 4, 3).getTime()
248
+ });
249
+ assert.deepEqual(result, [
250
+ "/2026"
251
+ ]);
252
+ });
253
+ test("multiple suffix parts", async () => {
254
+ const collections = {
255
+ invoices: {
256
+ policy: {
257
+ suffix: [
258
+ { key: "type" },
259
+ {
260
+ key: "date",
261
+ type: "date:YYYY"
262
+ }
263
+ ]
264
+ }
265
+ }
266
+ };
267
+ const result = await applySuffixPolicy(collections, "invoices", {
268
+ type: "Sales",
269
+ date: new Date(2026, 4, 3).getTime()
270
+ });
271
+ assert.deepEqual(result, [
272
+ "/Sales/2026"
273
+ ]);
274
+ });
275
+ test("range policy", async () => {
276
+ const collections = {
277
+ invoices: {
278
+ policy: {
279
+ when: {
280
+ age: {
281
+ $gt: 10
282
+ }
283
+ },
284
+ suffix: [
285
+ { key: "type" }
286
+ ]
287
+ }
288
+ }
289
+ };
290
+ const result = await applySuffixPolicy(collections, "invoices", {
291
+ age: {
292
+ $gt: 20
293
+ },
294
+ type: "Sales"
295
+ });
296
+ assert.deepEqual(result, [
297
+ "/Sales"
298
+ ]);
299
+ });
300
+ test("range policy miss", async () => {
301
+ const collections = {
302
+ invoices: {
303
+ policy: {
304
+ when: {
305
+ age: {
306
+ $gt: 50
307
+ }
308
+ },
309
+ suffix: [
310
+ { key: "type" }
311
+ ]
312
+ }
313
+ }
314
+ };
315
+ const result = await applySuffixPolicy(collections, "invoices", {
316
+ age: {
317
+ $lt: 10
318
+ },
319
+ type: "Sales"
320
+ });
321
+ assert.deepEqual(result, []);
322
+ });
323
+ test("$ne throws", async () => {
324
+ const collections = {
325
+ invoices: {
326
+ policy: {
327
+ when: {
328
+ status: {
329
+ $ne: "Deleted"
330
+ }
331
+ },
332
+ suffix: [
333
+ { key: "type" }
334
+ ]
335
+ }
336
+ }
337
+ };
338
+ await assert.rejects(async () => {
339
+ await applySuffixPolicy(collections, "invoices", {
340
+ status: "Active",
341
+ type: "Sales"
342
+ });
343
+ });
344
+ });
345
+ test("policy value inside query range", async () => {
346
+ const collections = {
347
+ invoices: {
348
+ policy: {
349
+ when: {
350
+ age: { $in: [10] }
351
+ },
352
+ suffix: [
353
+ { key: "type" }
354
+ ]
355
+ }
356
+ }
357
+ };
358
+ const result = await applySuffixPolicy(collections, "invoices", {
359
+ age: {
360
+ $gt: 5,
361
+ $lt: 15
362
+ },
363
+ type: "Sales"
364
+ });
365
+ assert.deepEqual(result, [
366
+ "/Sales"
367
+ ]);
368
+ });
369
+ test("policy value outside query range", async () => {
370
+ const collections = {
371
+ invoices: {
372
+ policy: {
373
+ when: {
374
+ age: { $in: [20] }
375
+ },
376
+ suffix: [
377
+ { key: "type" }
378
+ ]
379
+ }
380
+ }
381
+ };
382
+ const result = await applySuffixPolicy(collections, "invoices", {
383
+ age: {
384
+ $gt: 5,
385
+ $lt: 15
386
+ },
387
+ type: "Sales"
388
+ });
389
+ assert.deepEqual(result, []);
390
+ });
391
+ test("policy range intersects query value", async () => {
392
+ const collections = {
393
+ invoices: {
394
+ policy: {
395
+ when: {
396
+ age: {
397
+ $gt: 5,
398
+ $lt: 15
399
+ }
400
+ },
401
+ suffix: [
402
+ { key: "type" }
403
+ ]
404
+ }
405
+ }
406
+ };
407
+ const result = await applySuffixPolicy(collections, "invoices", {
408
+ age: { $in: [10] },
409
+ type: "Sales"
410
+ });
411
+ assert.deepEqual(result, [
412
+ "/Sales"
413
+ ]);
414
+ });
415
+ test("policy range does not intersect query value", async () => {
416
+ const collections = {
417
+ invoices: {
418
+ policy: {
419
+ when: {
420
+ age: {
421
+ $gt: 20,
422
+ $lt: 30
423
+ }
424
+ },
425
+ suffix: [
426
+ { key: "type" }
427
+ ]
428
+ }
429
+ }
430
+ };
431
+ const result = await applySuffixPolicy(collections, "invoices", {
432
+ age: { $in: [10] },
433
+ type: "Sales"
434
+ });
435
+ assert.deepEqual(result, []);
436
+ });
437
+ test("policy range intersects query range", async () => {
438
+ const collections = {
439
+ invoices: {
440
+ policy: {
441
+ when: {
442
+ age: {
443
+ $gt: 10,
444
+ $lt: 30
445
+ }
446
+ },
447
+ suffix: [
448
+ { key: "type" }
449
+ ]
450
+ }
451
+ }
452
+ };
453
+ const result = await applySuffixPolicy(collections, "invoices", {
454
+ age: {
455
+ $gt: 20,
456
+ $lt: 40
457
+ },
458
+ type: "Sales"
459
+ });
460
+ assert.deepEqual(result, [
461
+ "/Sales"
462
+ ]);
463
+ });
464
+ test("policy range does not intersect query range", async () => {
465
+ const collections = {
466
+ invoices: {
467
+ policy: {
468
+ when: {
469
+ age: {
470
+ $gt: 50,
471
+ $lt: 60
472
+ }
473
+ },
474
+ suffix: [
475
+ { key: "type" }
476
+ ]
477
+ }
478
+ }
479
+ };
480
+ const result = await applySuffixPolicy(collections, "invoices", {
481
+ age: {
482
+ $gt: 10,
483
+ $lt: 20
484
+ },
485
+ type: "Sales"
486
+ });
487
+ assert.deepEqual(result, []);
488
+ });
489
+ });