corebasic 1.0.212 → 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 (141) 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/package.json +3 -2
  26. package/tsc/@typescript/typescript-linux-x64/LICENSE +55 -0
  27. package/tsc/@typescript/typescript-linux-x64/NOTICE.txt +436 -0
  28. package/tsc/@typescript/typescript-linux-x64/README.md +3 -0
  29. package/tsc/@typescript/typescript-linux-x64/lib/lib.d.ts +20 -0
  30. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.d.ts +382 -0
  31. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.legacy.d.ts +20 -0
  32. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.asynciterable.d.ts +18 -0
  33. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.d.ts +45125 -0
  34. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.iterable.d.ts +18 -0
  35. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.collection.d.ts +159 -0
  36. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.core.d.ts +595 -0
  37. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.d.ts +26 -0
  38. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.generator.d.ts +75 -0
  39. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.iterable.d.ts +603 -0
  40. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.promise.d.ts +79 -0
  41. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.proxy.d.ts +126 -0
  42. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.reflect.d.ts +142 -0
  43. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.d.ts +44 -0
  44. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
  45. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.array.include.d.ts +114 -0
  46. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.d.ts +19 -0
  47. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.full.d.ts +21 -0
  48. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.intl.d.ts +29 -0
  49. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.arraybuffer.d.ts +19 -0
  50. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.d.ts +24 -0
  51. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.date.d.ts +29 -0
  52. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.full.d.ts +21 -0
  53. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.intl.d.ts +42 -0
  54. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.object.d.ts +47 -0
  55. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.sharedmemory.d.ts +133 -0
  56. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.string.d.ts +47 -0
  57. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.typedarrays.d.ts +51 -0
  58. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asyncgenerator.d.ts +75 -0
  59. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asynciterable.d.ts +51 -0
  60. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.d.ts +22 -0
  61. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.full.d.ts +22 -0
  62. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.intl.d.ts +81 -0
  63. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.promise.d.ts +28 -0
  64. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.regexp.d.ts +35 -0
  65. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.array.d.ts +77 -0
  66. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.d.ts +22 -0
  67. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.full.d.ts +22 -0
  68. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.intl.d.ts +21 -0
  69. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.object.d.ts +31 -0
  70. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.string.d.ts +35 -0
  71. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.symbol.d.ts +22 -0
  72. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.bigint.d.ts +763 -0
  73. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.d.ts +25 -0
  74. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.date.d.ts +40 -0
  75. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.full.d.ts +22 -0
  76. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.intl.d.ts +472 -0
  77. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.number.d.ts +26 -0
  78. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.promise.d.ts +45 -0
  79. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.sharedmemory.d.ts +97 -0
  80. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.string.d.ts +42 -0
  81. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
  82. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.d.ts +21 -0
  83. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.full.d.ts +22 -0
  84. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.intl.d.ts +164 -0
  85. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.promise.d.ts +46 -0
  86. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.string.d.ts +31 -0
  87. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.weakref.d.ts +76 -0
  88. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.array.d.ts +119 -0
  89. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.d.ts +23 -0
  90. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.error.d.ts +73 -0
  91. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.full.d.ts +22 -0
  92. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.intl.d.ts +143 -0
  93. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.object.d.ts +24 -0
  94. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.regexp.d.ts +37 -0
  95. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.string.d.ts +23 -0
  96. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.array.d.ts +922 -0
  97. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.collection.d.ts +19 -0
  98. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.d.ts +20 -0
  99. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.full.d.ts +22 -0
  100. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.intl.d.ts +62 -0
  101. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.arraybuffer.d.ts +63 -0
  102. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.collection.d.ts +27 -0
  103. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.d.ts +24 -0
  104. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.full.d.ts +22 -0
  105. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.object.d.ts +27 -0
  106. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.promise.d.ts +33 -0
  107. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.regexp.d.ts +23 -0
  108. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.sharedmemory.d.ts +66 -0
  109. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.string.d.ts +27 -0
  110. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.collection.d.ts +94 -0
  111. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.d.ts +23 -0
  112. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.float16.d.ts +443 -0
  113. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.full.d.ts +22 -0
  114. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.intl.d.ts +200 -0
  115. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.iterator.d.ts +146 -0
  116. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.promise.d.ts +32 -0
  117. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.regexp.d.ts +30 -0
  118. package/tsc/@typescript/typescript-linux-x64/lib/lib.es5.d.ts +4599 -0
  119. package/tsc/@typescript/typescript-linux-x64/lib/lib.es6.d.ts +21 -0
  120. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.array.d.ts +33 -0
  121. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.collection.d.ts +47 -0
  122. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.d.ts +27 -0
  123. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.date.d.ts +21 -0
  124. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.decorators.d.ts +26 -0
  125. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.disposable.d.ts +191 -0
  126. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.error.d.ts +22 -0
  127. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.full.d.ts +22 -0
  128. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.intl.d.ts +107 -0
  129. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.sharedmemory.d.ts +23 -0
  130. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.temporal.d.ts +485 -0
  131. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.typedarrays.d.ts +90 -0
  132. package/tsc/@typescript/typescript-linux-x64/lib/lib.scripthost.d.ts +320 -0
  133. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.asynciterable.d.ts +18 -0
  134. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.d.ts +15606 -0
  135. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.importscripts.d.ts +21 -0
  136. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.iterable.d.ts +18 -0
  137. package/tsc/@typescript/typescript-linux-x64/lib/tsc +0 -0
  138. package/tsc/@typescript/typescript-linux-x64/lib/tsc.sig +11 -0
  139. package/tsc/@typescript/typescript-linux-x64/package.json +45 -0
  140. package/tsc/notes +14 -0
  141. package/tsconfig.json +48 -0
@@ -0,0 +1,102 @@
1
+ import * as Elabase from './elabase.js';
2
+ export const start = Elabase.start;
3
+ export const operation = Elabase.operation;
4
+ export const insert = Elabase.insert;
5
+ export const query = Elabase.query;
6
+ export const update = Elabase.update;
7
+ export const remove = Elabase.remove;
8
+ export const newRaw = Elabase.newRaw;
9
+ export const batchBegin = Elabase.batchBegin;
10
+ export const batchAbort = Elabase.batchAbort;
11
+ export const batchSubmit = Elabase.batchSubmit;
12
+ export const batch = Elabase.batch;
13
+ export const globalMeta = Elabase.globalMeta;
14
+ export const companyMeta = Elabase.companyMeta;
15
+ export const outletMeta = Elabase.outletMeta;
16
+ export const customMeta = Elabase.customMeta;
17
+ export const schema = Elabase.schema;
18
+ export const isDipMeta = Elabase.isDipMeta;
19
+ export const excludeCollectionConfig = Elabase.excludeCollectionConfig;
20
+ export const includeCollectionConfig = Elabase.includeCollectionConfig;
21
+ export const shard_stats = Elabase.shard_stats;
22
+ export let config = Elabase.config;
23
+ export async function insertSync(meta, feature, date, uid, ref, type) {
24
+ let stamp = new Date(date).toISOString();
25
+ let _id = `${meta.outlet}_${stamp}_${uid}`;
26
+ let data = { _id, ref, type: type === "REMOVE" ? type : "UPSERT" };
27
+ let collection = 'syncs.' + feature;
28
+ await Elabase.insert(meta, collection, data);
29
+ }
30
+ export const IdempotentDip = () => {
31
+ return {
32
+ txn: '',
33
+ meta: undefined,
34
+ new: (async function (meta, txn, blank) {
35
+ this.txn = txn;
36
+ this.meta = meta;
37
+ return blank ? this : ((await Elabase.query(this.meta, "txns", { _id: this.txn })).length ? false : this);
38
+ }),
39
+ insert: (async function (collection, query, data) {
40
+ await Elabase.update(this.meta, collection, query, { $setOnInsert: data }, { upsert: true });
41
+ }),
42
+ update: (async function (collection, query, data, rollback) {
43
+ let token = { [this.txn]: true };
44
+ let idempotent = { [this.txn]: { $exists: rollback ?? false } };
45
+ let result = await Elabase.update(this.meta, collection, { ...query, ...idempotent }, { ...data, $setOnInsert: undefined, $set: { ...(data.$set ?? {}), ...token } });
46
+ return result.count ? true : (await Elabase.query(this.meta, collection, { ...query, ...idempotent })).length;
47
+ }),
48
+ upsert: (async function (collection, query, data, rollback) {
49
+ await this.insert(collection, query, data.$setOnInsert);
50
+ return await this.update(collection, query, data, rollback);
51
+ }),
52
+ cleanup: (async function (collection, query) {
53
+ await Elabase.update(this.meta, collection, query, { $unset: { [this.txn]: true } });
54
+ }),
55
+ finish: (async function () {
56
+ return await Elabase.update(this.meta, "txns", { _id: this.txn }, {}, { upsert: true });
57
+ })
58
+ };
59
+ };
60
+ export const idip = async (message, callback, cleanup) => {
61
+ if (!callback)
62
+ throw new Error("Dip.idip() callback argument undefined");
63
+ if (!cleanup)
64
+ throw new Error("Dip.idip() cleanup argument undefined");
65
+ async function doCleanup(IDip) {
66
+ if (typeof cleanup === 'object') {
67
+ for (let collection in cleanup)
68
+ await IDip.cleanup(collection, { _id: { $in: cleanup[collection] } });
69
+ }
70
+ else
71
+ await cleanup(IDip);
72
+ }
73
+ let IDip = await IdempotentDip().new(message.meta, message.txn);
74
+ if (!IDip) {
75
+ IDip = await IdempotentDip().new(message.meta, message.txn, { blank: true });
76
+ await doCleanup(IDip);
77
+ return;
78
+ }
79
+ await callback(IDip);
80
+ await IDip.finish();
81
+ await doCleanup(IDip);
82
+ };
83
+ export const insertKeys = (message, meta) => {
84
+ if (!isDipMeta(meta))
85
+ throw new Error('Error: Provided meta is not an instance of DipMeta in Dip.insertKeys()');
86
+ return {
87
+ "created": message.date, "updated": message.date,
88
+ "createdBy": message.meta.staff,
89
+ "updatedBy": message.meta.staff,
90
+ "createdByUser": message.meta.user,
91
+ "updatedByUser": message.meta.user,
92
+ ...(meta?.company ? { "company": meta.company } : {}),
93
+ ...(meta?.outlet ? { "outlet": meta.outlet } : {}),
94
+ };
95
+ };
96
+ export const updateKeys = message => {
97
+ return {
98
+ "updated": message.date,
99
+ "updatedBy": message.meta.staff,
100
+ "updatedByUser": message.meta.user,
101
+ };
102
+ };
@@ -0,0 +1,73 @@
1
+ import axios from 'axios';
2
+ // import {curly} from 'node-libcurl'
3
+ function hashStr(str) {
4
+ let hash = 0;
5
+ for (let i = 0; i < str.length; i++) {
6
+ let charCode = str.charCodeAt(i);
7
+ hash += charCode;
8
+ }
9
+ return hash;
10
+ }
11
+ function hash(string, digits) {
12
+ digits = digits || 6;
13
+ var m = Math.pow(10, digits + 1) - 1;
14
+ var phi = Math.pow(10, digits) / 2 - 1;
15
+ var n = 0;
16
+ for (var i = 0; i < string.length; i++) {
17
+ n = (n + phi * string.charCodeAt(i)) % m;
18
+ }
19
+ return n.toString();
20
+ }
21
+ let shards = [];
22
+ let shardCount = 20;
23
+ for (let i = 1; i <= shardCount; i++)
24
+ shards.push(`127.0.0.1:${9500 + i}`);
25
+ // function shard(key) {
26
+ // return hash(key,1) % shardCount
27
+ // }
28
+ function shard(key) {
29
+ return hashStr(key) % shardCount;
30
+ }
31
+ export let shard_hits = {};
32
+ async function postDip(url, arg) {
33
+ return (await axios.post(url, arg)).data;
34
+ // curl
35
+ // -----
36
+ // const { data } = await curly.post(url, {
37
+ // postFields: JSON.stringify(arg),
38
+ // httpHeader: [
39
+ // 'Content-Type: application/json',
40
+ // 'Accept: application/json'
41
+ // ],
42
+ // })
43
+ // return data
44
+ }
45
+ export default async function dipper(arg) {
46
+ let result = [];
47
+ let _id = arg.query?._id ?? arg.insert?._id ?? undefined;
48
+ if (!_id) {
49
+ let result = [];
50
+ for (let url of shards) {
51
+ shard_hits[url] = (shard_hits[url] ?? 0) + 1;
52
+ result.push(await postDip(`http://${url}/execute`, arg));
53
+ }
54
+ }
55
+ else {
56
+ let ids = typeof _id == "object" ? _id.$in : [_id];
57
+ for (let id of ids) {
58
+ let key = shard(id);
59
+ let url = shards[key];
60
+ shard_hits[url] = (shard_hits[url] ?? 0) + 1;
61
+ result.push(await postDip(`http://${url}/execute`, arg));
62
+ }
63
+ }
64
+ if (arg.mode === "query")
65
+ result = result.reduce((partial, item) => partial.concat(item), []);
66
+ return arg.mode === "query" ? result : result[0];
67
+ }
68
+ export const shard_stats = () => {
69
+ let total = Object.values(shard_hits).reduce((partial, value) => partial + value, 0);
70
+ let result = {};
71
+ Object.entries(shard_hits).forEach(([key, value]) => result[key] = parseFloat(value * 100 / total).toFixed(2));
72
+ return result;
73
+ };