@lango-project/lango-boss 0.0.0-stage → 0.1.1

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 (121) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +118 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/entries/cli.mjs +139 -0
  6. package/dist/.lango/entries/cli.mjs.map +1 -0
  7. package/dist/.lango/localization.mjs +108 -0
  8. package/dist/.lango/runtime.mjs +725 -0
  9. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  10. package/dist/.lango/vendor/i18next.mjs +2434 -0
  11. package/dist/.lango/xmldom/conventions.js +429 -0
  12. package/dist/.lango/xmldom/dom-parser.js +591 -0
  13. package/dist/.lango/xmldom/dom.js +3759 -0
  14. package/dist/.lango/xmldom/entities.js +2171 -0
  15. package/dist/.lango/xmldom/errors.js +205 -0
  16. package/dist/.lango/xmldom/grammar.js +559 -0
  17. package/dist/.lango/xmldom/index.js +41 -0
  18. package/dist/.lango/xmldom/package.json +1 -0
  19. package/dist/.lango/xmldom/sax.js +983 -0
  20. package/dist/.lango/xmldom.LICENSE.md +8 -0
  21. package/dist/boss.mjs +136 -0
  22. package/dist/boss.mjs.map +1 -0
  23. package/dist/claim_watch.mjs +99 -0
  24. package/dist/claim_watch.mjs.map +1 -0
  25. package/dist/cli.mjs +7 -0
  26. package/dist/cli.mjs.map +1 -0
  27. package/dist/configuration.mjs +58 -0
  28. package/dist/configuration.mjs.map +1 -0
  29. package/dist/dispatcher.mjs +108 -0
  30. package/dist/dispatcher.mjs.map +1 -0
  31. package/dist/driver.mjs +98 -0
  32. package/dist/driver.mjs.map +1 -0
  33. package/dist/envelope.mjs +92 -0
  34. package/dist/envelope.mjs.map +1 -0
  35. package/dist/library.mjs +139 -0
  36. package/dist/library.mjs.map +1 -0
  37. package/dist/management.mjs +360 -0
  38. package/dist/management.mjs.map +1 -0
  39. package/dist/management_transaction.mjs +26 -0
  40. package/dist/management_transaction.mjs.map +1 -0
  41. package/dist/namespace.mjs +27 -0
  42. package/dist/namespace.mjs.map +1 -0
  43. package/dist/queue.mjs +161 -0
  44. package/dist/queue.mjs.map +1 -0
  45. package/dist/reads.mjs +359 -0
  46. package/dist/reads.mjs.map +1 -0
  47. package/dist/retention.mjs +133 -0
  48. package/dist/retention.mjs.map +1 -0
  49. package/dist/schedule_sync.mjs +222 -0
  50. package/dist/schedule_sync.mjs.map +1 -0
  51. package/dist/schedule_transaction.mjs +24 -0
  52. package/dist/schedule_transaction.mjs.map +1 -0
  53. package/dist/schedules.mjs +201 -0
  54. package/dist/schedules.mjs.map +1 -0
  55. package/dist/transaction.mjs +16 -0
  56. package/dist/transaction.mjs.map +1 -0
  57. package/dist/validation.mjs +90 -0
  58. package/dist/validation.mjs.map +1 -0
  59. package/dist/worker.mjs +316 -0
  60. package/dist/worker.mjs.map +1 -0
  61. package/docs/guide.md +88 -0
  62. package/docs/management.md +93 -0
  63. package/docs/producer.md +115 -0
  64. package/docs/reads.md +107 -0
  65. package/docs/reference.md +77 -0
  66. package/docs/release.md +103 -0
  67. package/docs/retention.md +47 -0
  68. package/docs/scheduling.md +79 -0
  69. package/docs/worker.md +90 -0
  70. package/examples/reports/README.md +118 -0
  71. package/examples/reports/app.lango +133 -0
  72. package/examples/reports/deploy.xml +6 -0
  73. package/examples/reports/dist/.lango/bignumber.mjs +3119 -0
  74. package/examples/reports/dist/.lango/entries/app.mjs +133 -0
  75. package/examples/reports/dist/.lango/entries/app.mjs.map +1 -0
  76. package/examples/reports/dist/.lango/localization.mjs +108 -0
  77. package/examples/reports/dist/.lango/runtime.mjs +725 -0
  78. package/examples/reports/dist/.lango/vendor/i18next.LICENSE +21 -0
  79. package/examples/reports/dist/.lango/vendor/i18next.mjs +2434 -0
  80. package/examples/reports/dist/.lango/xmldom/conventions.js +429 -0
  81. package/examples/reports/dist/.lango/xmldom/dom-parser.js +591 -0
  82. package/examples/reports/dist/.lango/xmldom/dom.js +3759 -0
  83. package/examples/reports/dist/.lango/xmldom/entities.js +2171 -0
  84. package/examples/reports/dist/.lango/xmldom/errors.js +205 -0
  85. package/examples/reports/dist/.lango/xmldom/grammar.js +559 -0
  86. package/examples/reports/dist/.lango/xmldom/index.js +41 -0
  87. package/examples/reports/dist/.lango/xmldom/package.json +1 -0
  88. package/examples/reports/dist/.lango/xmldom/sax.js +983 -0
  89. package/examples/reports/dist/.lango/xmldom.LICENSE.md +8 -0
  90. package/examples/reports/dist/app.mjs +7 -0
  91. package/examples/reports/dist/app.mjs.map +1 -0
  92. package/examples/reports/dist/handlers.mjs +202 -0
  93. package/examples/reports/dist/handlers.mjs.map +1 -0
  94. package/examples/reports/dist/setup.mjs +14 -0
  95. package/examples/reports/dist/setup.mjs.map +1 -0
  96. package/examples/reports/handlers.lango +153 -0
  97. package/examples/reports/jobs.xml +5 -0
  98. package/examples/reports/package.json +23 -0
  99. package/examples/reports/routes.xml +4 -0
  100. package/examples/reports/setup.lango +17 -0
  101. package/package.json +62 -4
  102. package/src/boss.lango +92 -0
  103. package/src/claim_watch.lango +58 -0
  104. package/src/cli.lango +103 -0
  105. package/src/configuration.lango +43 -0
  106. package/src/dispatcher.lango +75 -0
  107. package/src/driver.lango +72 -0
  108. package/src/envelope.lango +56 -0
  109. package/src/library.lango +66 -0
  110. package/src/management.lango +302 -0
  111. package/src/management_transaction.lango +28 -0
  112. package/src/namespace.lango +15 -0
  113. package/src/queue.lango +115 -0
  114. package/src/reads.lango +277 -0
  115. package/src/retention.lango +107 -0
  116. package/src/schedule_sync.lango +190 -0
  117. package/src/schedule_transaction.lango +22 -0
  118. package/src/schedules.lango +165 -0
  119. package/src/transaction.lango +23 -0
  120. package/src/validation.lango +45 -0
  121. package/src/worker.lango +230 -0
@@ -0,0 +1,27 @@
1
+ import * as crypto from "node:crypto";
2
+ import {
3
+ normalize as __normalize,
4
+ boundary as __boundary,
5
+ requireArity as __requireArity,
6
+ } from "./.lango/runtime.mjs";
7
+
8
+ export function schemaName(application) {
9
+ __requireArity(arguments.length, [0], "schemaName");
10
+ application = __boundary(application);
11
+ let hash = __normalize(crypto.createHash("sha256"));
12
+ __normalize(hash.update(application));
13
+ let suffix = __normalize(__normalize(hash.digest("hex")).slice(0, 32));
14
+ return `lango_${suffix}`;
15
+ return null;
16
+ }
17
+
18
+ export function scheduleKey(application, name) {
19
+ __requireArity(arguments.length, [0, 1], "scheduleKey");
20
+ application = __boundary(application);
21
+ name = __boundary(name);
22
+ let hash = __normalize(crypto.createHash("sha256"));
23
+ __normalize(hash.update(name));
24
+ return `${schemaName(application)}/${__normalize(hash.digest("hex"))}`;
25
+ return null;
26
+ }
27
+ //# sourceMappingURL=namespace.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.mjs","sources":["namespace.lango"],"sourcesContent":["import js \"node:crypto\" as crypto\n\nexport schemaName(application)\nexport scheduleKey(application, name)\n\nschemaName(application)\n hash = crypto/createHash(\"sha256\")\n hash.update(application)\n suffix = hash.digest(\"hex\").slice(0, 32)\n return \"lango_${suffix}\"\n\nscheduleKey(application, name)\n hash = crypto/createHash(\"sha256\")\n hash.update(name)\n return \"${schemaName(application)}/${hash.digest(\"hex\")}\"\n"],"names":[],"mappings":";;;;;;;AAKA;;;;;;;;;;AAMA;;;;;;;;;;","x_lango_build":{"fingerprint":"cc74bf96a88652b6a4db59981efcc8128328503c4412e09922db3b92749ab8ca","outputHash":"0bfacea8c3f9ba01bb40435aac1f57bfb1f96aa907a3e07ddf230c155007f91b","mapHash":"d032f533307fa63a98e5ed58f7ca83fe9e9f0d473ab0409e4525c6e2ef4d818f"}}
package/dist/queue.mjs ADDED
@@ -0,0 +1,161 @@
1
+ import { readJob, readJobs } from "./reads.mjs";
2
+ import { manage as management } from "./management.mjs";
3
+ import {
4
+ hostGlobal as __hostGlobal,
5
+ contextGet as __contextGet,
6
+ contextSet as __contextSet,
7
+ contextRestore as __contextRestore,
8
+ fromJson as __fromJson,
9
+ toJson as __toJson,
10
+ isNumber as __isNumber,
11
+ isString as __isString,
12
+ isBool as __isBool,
13
+ isObject as __isObject,
14
+ isArray as __isArray,
15
+ requireBoolean as __requireBoolean,
16
+ normalize as __normalize,
17
+ finite as __finite,
18
+ boundary as __boundary,
19
+ requireArity as __requireArity,
20
+ } from "./.lango/runtime.mjs";
21
+
22
+ class QueueSender {
23
+ #settings;
24
+ #db;
25
+ #token;
26
+ #lango;
27
+ constructor(settings, db, token) {
28
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
29
+ settings = __boundary(settings);
30
+ db = __boundary(db);
31
+ token = __boundary(token);
32
+ this.#settings = __fromJson(__toJson(settings));
33
+ this.#db = db;
34
+ this.#token = token;
35
+ }
36
+ get(id) {
37
+ __requireArity(arguments.length, [0], "get");
38
+ id = __boundary(id);
39
+ return readJob(__normalize(this.#settings), __normalize(this.#db), __normalize(this.#token), id);
40
+ return null;
41
+ }
42
+ job(id) {
43
+ __requireArity(arguments.length, [0], "job");
44
+ id = __boundary(id);
45
+ return readJob(__normalize(this.#settings), __normalize(this.#db), __normalize(this.#token), id, true);
46
+ return null;
47
+ }
48
+ jobs(options = null) {
49
+ options = __boundary(options);
50
+ return readJobs(__normalize(this.#settings), __normalize(this.#db), __normalize(this.#token), options);
51
+ return null;
52
+ }
53
+ manage(action, target = null, options = null) {
54
+ __requireArity(arguments.length, [0], "manage");
55
+ action = __boundary(action);
56
+ target = __boundary(target);
57
+ options = __boundary(options);
58
+ return management(__normalize(this.#settings), __normalize(this.#db), __normalize(this.#token), action, target, options);
59
+ return null;
60
+ }
61
+ send(path, input) {
62
+ const __contextScope = [];
63
+ try {
64
+ __requireArity(arguments.length, [0, 1], "send");
65
+ path = __boundary(path);
66
+ input = __boundary(input);
67
+ let target = null;
68
+ for (const candidate of __normalize(this.#settings.targets)) {
69
+ if (__requireBoolean(__normalize(candidate.path) === path)) {
70
+ target = candidate;
71
+ }
72
+ }
73
+ if (__requireBoolean(target === null)) {
74
+ throw `Unknown job path: ${path}`;
75
+ }
76
+ if (__requireBoolean(__requireBoolean(__requireBoolean(input === null) || __requireBoolean(!__requireBoolean(__isObject(input)))) || __requireBoolean(__isArray(input)))) {
77
+ throw "Queue input must be a JSON map";
78
+ }
79
+ if (__requireBoolean(__requireBoolean(__normalize(target.policy) !== "anonymous") && __requireBoolean(!__requireBoolean(__normalize(this.#token.hasPolicy(__normalize(target.policy))))))) {
80
+ throw `Queue target policy rejected: ${__normalize(target.policy)}`;
81
+ }
82
+ if (__requireBoolean(__normalize(target.reauthSeconds) > 0)) {
83
+ let stamp = __normalize(this.#token.get("authenticatedAt"));
84
+ let now = __normalize(__hostGlobal(["Date"]).now());
85
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(stamp)))) || __requireBoolean(stamp < 0)) || __requireBoolean(stamp > now)) || __requireBoolean(__finite(now - stamp) >= __finite(__normalize(target.reauthSeconds) * 1000)))) {
86
+ throw "Queue target requires fresh authentication";
87
+ }
88
+ }
89
+ let payload = { version: 1, application: __normalize(this.#settings.application), path: __normalize(target.path), input: __fromJson(__toJson(input)), source: source(__normalize(this.#token)), failedRetentionSeconds: 604800 };
90
+ let state = __normalize(this.#db.transactionState());
91
+ if (__requireBoolean(__requireBoolean(state !== null) && __requireBoolean(state !== "active"))) {
92
+ throw "Queue submission requires a usable transaction";
93
+ }
94
+ let own = state === null;
95
+ if (__requireBoolean(own)) {
96
+ __normalize(this.#db.begin());
97
+ }
98
+ try {
99
+ let id = __normalize(this.#db.invoke({ module: "@lango-project/lango-boss/transaction", handler: "send" }, { schema: __normalize(this.#settings.schema), queue: __normalize(target.queue), payload: payload }));
100
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(id))) || __requireBoolean(id === ""))) {
101
+ throw "Queue submission did not return a job id";
102
+ }
103
+ if (__requireBoolean(own)) {
104
+ __normalize(this.#db.commit());
105
+ }
106
+ return id;
107
+ } catch (error) {
108
+ if (__requireBoolean(own)) {
109
+ try {
110
+ __normalize(this.#db.rollback());
111
+ } catch (rollbackError) {
112
+ __normalize(__contextGet("log").err("Queue transaction cleanup failed"));
113
+ }
114
+ }
115
+ throw error;
116
+ }
117
+ return null;
118
+ } finally {
119
+ __contextRestore(__contextScope);
120
+ }
121
+ }
122
+ }
123
+ export function createQueue(settings) {
124
+ const __contextScope = [];
125
+ try {
126
+ __requireArity(arguments.length, [0], "createQueue");
127
+ settings = __boundary(settings);
128
+ if (__requireBoolean(__requireBoolean(__contextGet("db") === null) || __requireBoolean(__normalize(__contextGet("db").parameterStyle) !== "postgresql"))) {
129
+ throw "Lango Boss queue requires an active PostgreSQL scope";
130
+ }
131
+ return new QueueSender(settings, __contextGet("db"), __contextGet("token"));
132
+ return null;
133
+ } finally {
134
+ __contextRestore(__contextScope);
135
+ }
136
+ }
137
+
138
+ function source(token) {
139
+ __requireArity(arguments.length, [0], "source");
140
+ token = __boundary(token);
141
+ let profile = __normalize(token.get("identity"));
142
+ if (__requireBoolean(__normalize(token.clientId) === null)) {
143
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(profile))) || __requireBoolean(profile === ""))) {
144
+ throw "Queue submission requires a trusted source identity";
145
+ }
146
+ return { kind: "system", identity: profile };
147
+ }
148
+ let result = { kind: "user", clientId: __normalize(token.clientId) };
149
+ for (const field of ["userId", "grantId"]) {
150
+ let value = __normalize(token.get(field));
151
+ if (__requireBoolean(value !== null)) {
152
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(value === ""))) {
153
+ throw "Queue identity references must be nonempty strings";
154
+ }
155
+ result[field] = value;
156
+ }
157
+ }
158
+ return result;
159
+ return null;
160
+ }
161
+ //# sourceMappingURL=queue.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.mjs","sources":["queue.lango"],"sourcesContent":["import js global Date\nimport js global Number\nimport \"./reads\"\n readJob(settings, db, token, id, management = false)\n readJobs(settings, db, token, options)\nimport \"./management\"\n alias management = manage(settings, scope, token, action, target = null, options = null)\n\nexport createQueue(settings)\n\nclass QueueSender(settings, db, token)\n methods\n send(path, input)\n get(id)\n job(id)\n jobs(options = null)\n manage(action, target = null, options = null)\n\ncreateQueue(settings)\n context db\n context token\n if db == null or db.parameterStyle != \"postgresql\"\n throw \"Lango Boss queue requires an active PostgreSQL scope\"\n return new QueueSender(settings, db, token)\n\nQueueSender(settings, db, token)\n @settings = from_json(to_json(settings))\n @db = db\n @token = token\n\nQueueSender:get(id)\n return readJob(@settings, @db, @token, id)\n\nQueueSender:job(id)\n return readJob(@settings, @db, @token, id, true)\n\nQueueSender:jobs(options = null)\n return readJobs(@settings, @db, @token, options)\n\nQueueSender:manage(action, target = null, options = null)\n return management(@settings, @db, @token, action, target, options)\n\nQueueSender:send(path, input)\n target = null\n for @settings.targets as candidate\n if candidate.path == path\n target = candidate\n if target == null\n throw \"Unknown job path: ${path}\"\n if input == null or !is_object(input) or is_array(input)\n throw \"Queue input must be a JSON map\"\n if target.policy != \"anonymous\" and !@token.hasPolicy(target.policy)\n throw \"Queue target policy rejected: ${target.policy}\"\n if target.reauthSeconds > 0\n stamp = @token.get(\"authenticatedAt\")\n now = Date/now()\n if !Number/isSafeInteger(stamp) or stamp < 0 or stamp > now or now - stamp >= target.reauthSeconds * 1000\n throw \"Queue target requires fresh authentication\"\n payload = {\n version: 1\n application: @settings.application\n path: target.path\n input: from_json(to_json(input))\n source: source(@token)\n failedRetentionSeconds: 604800\n }\n state = @db.transactionState()\n if state != null and state != \"active\"\n throw \"Queue submission requires a usable transaction\"\n own = state == null\n if own\n @db.begin()\n try\n id = @db.invoke({\n module: \"@lango-project/lango-boss/transaction\"\n handler: \"send\"\n }, {\n schema: @settings.schema\n queue: target.queue\n payload: payload\n })\n if !is_string(id) or id == \"\"\n throw \"Queue submission did not return a job id\"\n if own\n @db.commit()\n return id\n catch error\n if own\n try\n @db.rollback()\n catch rollbackError\n context log\n log.err(\"Queue transaction cleanup failed\")\n throw error\n\nsource(token)\n profile = token.get(\"identity\")\n if token.clientId? == null\n if !is_string(profile) or profile == \"\"\n throw \"Queue submission requires a trusted source identity\"\n return {\n kind: \"system\"\n identity: profile\n }\n result = {\n kind: \"user\"\n clientId: token.clientId?\n }\n for [\"userId\", \"grantId\"] as field\n value = token.get(field)\n if value != null\n if !is_string(value) or value == \"\"\n throw \"Queue identity references must be nonempty strings\"\n result[field] = value\n return result\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"cc208ead9cd3b40ce768bdcdf55f34ef3885b7cef3b223f839d4ffa9076ef0ff","outputHash":"3ef81bd86bc86f4e189b6feecb56b2bc7446ec72718065cf0831ff017ea61c7e","mapHash":"81418acc2eadb6342883a5a376689764117afc3d769a6fb5910a1851b0cd10a2"}}
package/dist/reads.mjs ADDED
@@ -0,0 +1,359 @@
1
+ import { schemaName } from "./namespace.mjs";
2
+ import {
3
+ hostGlobal as __hostGlobal,
4
+ contextGet as __contextGet,
5
+ contextSet as __contextSet,
6
+ contextRestore as __contextRestore,
7
+ fromJson as __fromJson,
8
+ toJson as __toJson,
9
+ isNumber as __isNumber,
10
+ isString as __isString,
11
+ isBool as __isBool,
12
+ isObject as __isObject,
13
+ isArray as __isArray,
14
+ entries as __entries,
15
+ requireBoolean as __requireBoolean,
16
+ normalize as __normalize,
17
+ finite as __finite,
18
+ numericAdd as __numericAdd,
19
+ boundary as __boundary,
20
+ query as __query,
21
+ requireArity as __requireArity,
22
+ } from "./.lango/runtime.mjs";
23
+
24
+ export function usable(db) {
25
+ __requireArity(arguments.length, [0], "usable");
26
+ db = __boundary(db);
27
+ let state = __normalize(db.transactionState());
28
+ if (__requireBoolean(__requireBoolean(state !== null) && __requireBoolean(state !== "active"))) {
29
+ throw "Job reads require a usable transaction";
30
+ }
31
+ return null;
32
+ return null;
33
+ }
34
+
35
+ export function manager(token) {
36
+ __requireArity(arguments.length, [0], "manager");
37
+ token = __boundary(token);
38
+ if (__requireBoolean(!__requireBoolean(__normalize(token.hasPolicy("boss.manage"))))) {
39
+ throw "Boss management policy required: boss.manage";
40
+ }
41
+ return null;
42
+ return null;
43
+ }
44
+
45
+ export function uuid(value) {
46
+ __requireArity(arguments.length, [0], "uuid");
47
+ value = __boundary(value);
48
+ let pattern = new (__hostGlobal(["RegExp"]))("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
49
+ return __requireBoolean(__isString(value)) && __requireBoolean(__normalize(pattern.test(value)));
50
+ return null;
51
+ }
52
+
53
+ function owned(source, token) {
54
+ __requireArity(arguments.length, [0, 1], "owned");
55
+ source = __boundary(source);
56
+ token = __boundary(token);
57
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(source === null) || __requireBoolean(!__requireBoolean(__isObject(source)))) || __requireBoolean(__isArray(source))) || __requireBoolean(__normalize(source.kind) !== "user")) || __requireBoolean(__normalize(source.identity) !== null))) {
58
+ return false;
59
+ }
60
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(source.clientId)))) || __requireBoolean(__normalize(source.clientId) === ""))) {
61
+ return false;
62
+ }
63
+ if (__requireBoolean(__normalize(source.clientId) !== __normalize(token.clientId))) {
64
+ return false;
65
+ }
66
+ for (const key of ["userId", "grantId"]) {
67
+ let expected = __normalize(source[key]);
68
+ if (__requireBoolean(__requireBoolean(expected !== null) && __requireBoolean(__requireBoolean(!__requireBoolean(__isString(expected))) || __requireBoolean(expected === "")))) {
69
+ return false;
70
+ }
71
+ if (__requireBoolean(expected !== __normalize(token.get(key)))) {
72
+ return false;
73
+ }
74
+ }
75
+ return true;
76
+ return null;
77
+ }
78
+
79
+ function permitted(settings, path, queue, token) {
80
+ __requireArity(arguments.length, [0, 1, 2, 3], "permitted");
81
+ settings = __boundary(settings);
82
+ path = __boundary(path);
83
+ queue = __boundary(queue);
84
+ token = __boundary(token);
85
+ for (const target of __normalize(settings.targets)) {
86
+ if (__requireBoolean(__requireBoolean(__normalize(target.path) === path) && __requireBoolean(__normalize(target.queue) === queue))) {
87
+ if (__requireBoolean(__requireBoolean(__normalize(target.policy) !== "anonymous") && __requireBoolean(!__requireBoolean(__normalize(token.hasPolicy(__normalize(target.policy))))))) {
88
+ return false;
89
+ }
90
+ if (__requireBoolean(__normalize(target.reauthSeconds) > 0)) {
91
+ let stamp = __normalize(token.get("authenticatedAt"));
92
+ let now = __normalize(__hostGlobal(["Date"]).now());
93
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(stamp)))) || __requireBoolean(stamp < 0)) || __requireBoolean(stamp > now)) || __requireBoolean(__finite(now - stamp) >= __finite(__normalize(target.reauthSeconds) * 1000)))) {
94
+ return false;
95
+ }
96
+ }
97
+ return true;
98
+ }
99
+ }
100
+ return false;
101
+ return null;
102
+ }
103
+
104
+ function invoke(settings, scope, action, input) {
105
+ const __contextScope = [];
106
+ try {
107
+ __requireArity(arguments.length, [0, 1, 2, 3], "invoke");
108
+ settings = __boundary(settings);
109
+ scope = __boundary(scope);
110
+ action = __boundary(action);
111
+ input = __boundary(input);
112
+ let single;
113
+ let result;
114
+ __contextScope.push(__contextSet("db", scope));
115
+ let schema = schemaName(__normalize(settings.application));
116
+ if (__requireBoolean(action === "job")) {
117
+ single = __query("select id::text, name as queue, data->>'path' as path, state::text,\n retry_count as \"retryCount\", retry_limit as \"retryLimit\",\n to_char(created_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"createdAt\",\n to_char(start_after at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startAfter\",\n to_char(started_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startedAt\",\n to_char(completed_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"completedAt\",\n data->'input' as input, data->'source' as source, output\nfrom " + String(schema) + ".job\nwhere id = :id::uuid and data->>'application' = :application\n and data->'version' = '1'::jsonb\nlimit 2", ["id","application"]);
118
+ single.id = __normalize(input.id);
119
+ single.application = __normalize(settings.application);
120
+ __normalize(single.execute());
121
+ if (__requireBoolean(!__requireBoolean(__normalize(single.next())))) {
122
+ return null;
123
+ }
124
+ result = summary(single);
125
+ result.input = __normalize(single.input);
126
+ result.source = __normalize(single.source);
127
+ result.output = __normalize(single.output);
128
+ if (__requireBoolean(__normalize(single.next()))) {
129
+ return null;
130
+ }
131
+ return result;
132
+ }
133
+ let listing = __query("select id::text, name as queue, data->>'path' as path, state::text,\n retry_count as \"retryCount\", retry_limit as \"retryLimit\",\n to_char(created_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"createdAt\",\n to_char(start_after at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startAfter\",\n to_char(started_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startedAt\",\n to_char(completed_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"completedAt\"\nfrom " + String(schema) + ".job\nwhere data->>'application' = :application and data->'version' = '1'::jsonb\n and (:queue::text is null or name = :queue)\n and (:path::text is null or data->>'path' = :path)\n and (:state::text is null or state::text = :state)\n and (:cursorTime::timestamptz is null or (created_on, id, name) < (:cursorTime::timestamptz, :cursorId::uuid, :cursorQueue::text))\norder by created_on desc, id desc, name desc\nlimit :limit", ["application","queue","path","state","cursorTime","cursorId","cursorQueue","limit"]);
134
+ listing.application = __normalize(settings.application);
135
+ listing.queue = __normalize(input.queue);
136
+ listing.path = __normalize(input.path);
137
+ listing.state = __normalize(input.state);
138
+ listing.limit = __normalize(input.limit);
139
+ listing.cursorTime = null;
140
+ listing.cursorId = null;
141
+ listing.cursorQueue = null;
142
+ if (__requireBoolean(__normalize(input.position) !== null)) {
143
+ listing.cursorTime = input.position.createdAt;
144
+ listing.cursorId = input.position.id;
145
+ listing.cursorQueue = input.position.name;
146
+ }
147
+ __normalize(listing.execute());
148
+ let rows = [];
149
+ __loop1: while (__requireBoolean(__normalize(listing.next()))) {
150
+ rows.push(summary(listing));
151
+ }
152
+ return rows;
153
+ return null;
154
+ } finally {
155
+ __contextRestore(__contextScope);
156
+ }
157
+ }
158
+
159
+ export function readJob(settings, db, token, id, management = false) {
160
+ __requireArity(arguments.length, [0, 1, 2, 3], "readJob");
161
+ settings = __boundary(settings);
162
+ db = __boundary(db);
163
+ token = __boundary(token);
164
+ id = __boundary(id);
165
+ management = __boundary(management);
166
+ usable(db);
167
+ if (__requireBoolean(management)) {
168
+ manager(token);
169
+ }
170
+ if (__requireBoolean(!__requireBoolean(uuid(id)))) {
171
+ return null;
172
+ }
173
+ let row = invoke(settings, db, "job", { id: id });
174
+ if (__requireBoolean(row === null)) {
175
+ return null;
176
+ }
177
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(management)) && __requireBoolean(__requireBoolean(!__requireBoolean(owned(__normalize(row.source), token))) || __requireBoolean(!__requireBoolean(permitted(settings, __normalize(row.path), __normalize(row.queue), token)))))) {
178
+ return null;
179
+ }
180
+ let result = summary(row);
181
+ result.resultAvailable = false;
182
+ result.result = null;
183
+ result.error = null;
184
+ let output = __normalize(row.output);
185
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(output !== null) && __requireBoolean(__isObject(output))) && __requireBoolean(!__requireBoolean(__isArray(output)))) && __requireBoolean(__normalize(output.version) === 1))) {
186
+ if (__requireBoolean(__requireBoolean(__normalize(row.state) === "completed") && __requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(output, "value"))))) {
187
+ result.resultAvailable = true;
188
+ result.result = __normalize(output.value);
189
+ }
190
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(row.state) === "failed") && __requireBoolean(__normalize(output.error) !== null)) && __requireBoolean(__isObject(__normalize(output.error))))) {
191
+ if (__requireBoolean(__requireBoolean(__isString(output.error.code)) && __requireBoolean(__isBool(output.error.permanent)))) {
192
+ result.error = { code: output.error.code, permanent: output.error.permanent };
193
+ }
194
+ }
195
+ }
196
+ if (__requireBoolean(management)) {
197
+ result.input = __normalize(row.input);
198
+ result.source = safeSource(__normalize(row.source));
199
+ }
200
+ return result;
201
+ return null;
202
+ }
203
+
204
+ function safeSource(source) {
205
+ __requireArity(arguments.length, [0], "safeSource");
206
+ source = __boundary(source);
207
+ let result = { };
208
+ if (__requireBoolean(__requireBoolean(__requireBoolean(source === null) || __requireBoolean(!__requireBoolean(__isObject(source)))) || __requireBoolean(__isArray(source)))) {
209
+ return null;
210
+ }
211
+ for (const field of ["kind", "clientId", "userId", "grantId", "identity"]) {
212
+ if (__requireBoolean(__isString(__normalize(source[field])))) {
213
+ result[field] = __normalize(source[field]);
214
+ }
215
+ }
216
+ return result;
217
+ return null;
218
+ }
219
+
220
+ function summary(row) {
221
+ __requireArity(arguments.length, [0], "summary");
222
+ row = __boundary(row);
223
+ return { id: __normalize(row.id), queue: __normalize(row.queue), path: __normalize(row.path), state: __normalize(row.state), retryCount: __normalize(row.retryCount), retryLimit: __normalize(row.retryLimit), createdAt: __normalize(row.createdAt), startAfter: __normalize(row.startAfter), startedAt: __normalize(row.startedAt), completedAt: __normalize(row.completedAt) };
224
+ return null;
225
+ }
226
+
227
+ function filters(options) {
228
+ __requireArity(arguments.length, [0], "filters");
229
+ options = __boundary(options);
230
+ if (__requireBoolean(options === null)) {
231
+ options = { };
232
+ }
233
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(options))) || __requireBoolean(__isArray(options)))) {
234
+ throw "Job list options must be a map";
235
+ }
236
+ let allowed = ["queue", "path", "state", "limit", "cursor"];
237
+ for (const [key, value] of __entries(options)) {
238
+ if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
239
+ throw `Unknown job list option: ${key}`;
240
+ }
241
+ }
242
+ let result = { queue: null, path: null, state: null, limit: 50, cursor: null };
243
+ for (const field of ["queue", "path", "state"]) {
244
+ let value = __normalize(options[field]);
245
+ if (__requireBoolean(value !== null)) {
246
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(value === "")) || __requireBoolean(__normalize(value.length) > 2048))) {
247
+ throw `Invalid job list filter: ${field}`;
248
+ }
249
+ result[field] = value;
250
+ }
251
+ }
252
+ let states = ["created", "retry", "active", "completed", "cancelled", "failed"];
253
+ if (__requireBoolean(__requireBoolean(__normalize(result.state) !== null) && __requireBoolean(!__requireBoolean(__normalize(states.includes(__normalize(result.state))))))) {
254
+ throw "Invalid job state filter";
255
+ }
256
+ if (__requireBoolean(__normalize(options.limit) !== null)) {
257
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(__normalize(options.limit))))) || __requireBoolean(__normalize(options.limit) < 1)) || __requireBoolean(__normalize(options.limit) > 200))) {
258
+ throw "Job list limit must be between 1 and 200";
259
+ }
260
+ result.limit = __normalize(options.limit);
261
+ }
262
+ if (__requireBoolean(__normalize(options.cursor) !== null)) {
263
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(options.cursor)))) || __requireBoolean(options.cursor.length === 0)) || __requireBoolean(options.cursor.length > 8192))) {
264
+ throw "Invalid job cursor";
265
+ }
266
+ result.cursor = __normalize(options.cursor);
267
+ }
268
+ return result;
269
+ return null;
270
+ }
271
+
272
+ function decodeCursor(settings, selected) {
273
+ __requireArity(arguments.length, [0, 1], "decodeCursor");
274
+ settings = __boundary(settings);
275
+ selected = __boundary(selected);
276
+ let bytes;
277
+ let value;
278
+ let pattern;
279
+ let stamp;
280
+ let date;
281
+ if (__requireBoolean(__normalize(selected.cursor) === null)) {
282
+ return null;
283
+ }
284
+ try {
285
+ bytes = __normalize(__hostGlobal(["Buffer"]).from(__normalize(selected.cursor), "base64url"));
286
+ if (__requireBoolean(__normalize(bytes.toString("base64url")) !== __normalize(selected.cursor))) {
287
+ throw "Invalid encoding";
288
+ }
289
+ value = __fromJson(__normalize(bytes.toString("utf8")));
290
+ if (__requireBoolean(__requireBoolean(__requireBoolean(value === null) || __requireBoolean(!__requireBoolean(__isObject(value)))) || __requireBoolean(__isArray(value)))) {
291
+ throw "Invalid cursor";
292
+ }
293
+ if (__requireBoolean(__requireBoolean(__normalize(value.version) !== 1) || __requireBoolean(__normalize(value.application) !== __normalize(settings.application)))) {
294
+ throw "Wrong cursor scope";
295
+ }
296
+ for (const field of ["queue", "path", "state"]) {
297
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(value, field)))) || __requireBoolean(__normalize(value[field]) !== __normalize(selected[field])))) {
298
+ throw "Changed cursor filters";
299
+ }
300
+ }
301
+ pattern = new (__hostGlobal(["RegExp"]))("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{6}Z$");
302
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(value.createdAt)))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(__normalize(value.createdAt)))))) || __requireBoolean(!__requireBoolean(uuid(__normalize(value.id))))) || __requireBoolean(!__requireBoolean(__isString(__normalize(value.name)))))) {
303
+ throw "Invalid cursor position";
304
+ }
305
+ stamp = __normalize(__hostGlobal(["Date"]).parse(__normalize(value.createdAt)));
306
+ if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isFinite(stamp))))) {
307
+ throw "Invalid cursor time";
308
+ }
309
+ date = new (__hostGlobal(["Date"]))(stamp);
310
+ if (__requireBoolean(__normalize(date.toISOString()) !== `${__normalize(value.createdAt.slice(0, 23))}Z`)) {
311
+ throw "Invalid cursor time";
312
+ }
313
+ if (__requireBoolean(__requireBoolean(value.name.length === 0) || __requireBoolean(value.name.length > 200))) {
314
+ throw "Invalid cursor queue";
315
+ }
316
+ return value;
317
+ } catch (error) {
318
+ throw "Invalid job cursor";
319
+ }
320
+ return null;
321
+ }
322
+
323
+ function encodeCursor(settings, selected, row) {
324
+ __requireArity(arguments.length, [0, 1, 2], "encodeCursor");
325
+ settings = __boundary(settings);
326
+ selected = __boundary(selected);
327
+ row = __boundary(row);
328
+ return __normalize(__normalize(__hostGlobal(["Buffer"]).from(__toJson({ version: 1, application: __normalize(settings.application), queue: __normalize(selected.queue), path: __normalize(selected.path), state: __normalize(selected.state), createdAt: __normalize(row.createdAt), id: __normalize(row.id), name: __normalize(row.queue) }), "utf8")).toString("base64url"));
329
+ return null;
330
+ }
331
+
332
+ export function readJobs(settings, db, token, options) {
333
+ __requireArity(arguments.length, [0, 1, 2, 3], "readJobs");
334
+ settings = __boundary(settings);
335
+ db = __boundary(db);
336
+ token = __boundary(token);
337
+ options = __boundary(options);
338
+ usable(db);
339
+ manager(token);
340
+ let selected = filters(options);
341
+ let cursor = decodeCursor(settings, selected);
342
+ let rows = invoke(settings, db, "jobs", { queue: __normalize(selected.queue), path: __normalize(selected.path), state: __normalize(selected.state), limit: __numericAdd(__normalize(selected.limit), 1), position: cursor });
343
+ let items = [];
344
+ let last = null;
345
+ for (const row of rows) {
346
+ if (__requireBoolean(__normalize(items.length) === __normalize(selected.limit))) {
347
+ break;
348
+ }
349
+ items.push(summary(row));
350
+ last = row;
351
+ }
352
+ let next = null;
353
+ if (__requireBoolean(__normalize(rows.length) > __normalize(selected.limit))) {
354
+ next = encodeCursor(settings, selected, last);
355
+ }
356
+ return { items: items, nextCursor: next };
357
+ return null;
358
+ }
359
+ //# sourceMappingURL=reads.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.mjs","sources":["reads.lango"],"sourcesContent":["import js global Date\nimport js global Number\nimport js global Object\nimport js global RegExp\nimport js global Buffer\nimport \"./namespace\"\n schemaName(application)\n\nexport readJob(settings, db, token, id, management = false)\nexport readJobs(settings, db, token, options)\nexport usable(db)\nexport manager(token)\nexport uuid(value)\n\nusable(db)\n state = db.transactionState()\n if state != null and state != \"active\"\n throw \"Job reads require a usable transaction\"\n return null\n\nmanager(token)\n if !token.hasPolicy(\"boss.manage\")\n throw \"Boss management policy required: boss.manage\"\n return null\n\nuuid(value)\n pattern = new RegExp(\"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\")\n return is_string(value) and pattern.test(value)\n\nowned(source, token)\n if source == null or !is_object(source) or is_array(source) or source.kind != \"user\" or source.identity != null\n return false\n if !is_string(source.clientId) or source.clientId == \"\"\n return false\n if source.clientId != token.clientId?\n return false\n for [\"userId\", \"grantId\"] as key\n expected = source[key]\n if expected != null and (!is_string(expected) or expected == \"\")\n return false\n if expected != token.get(key)\n return false\n return true\n\npermitted(settings, path, queue, token)\n for settings.targets as target\n if target.path == path and target.queue == queue\n if target.policy != \"anonymous\" and !token.hasPolicy(target.policy)\n return false\n if target.reauthSeconds > 0\n stamp = token.get(\"authenticatedAt\")\n now = Date/now()\n if !Number/isSafeInteger(stamp) or stamp < 0 or stamp > now or now - stamp >= target.reauthSeconds * 1000\n return false\n return true\n return false\n\ninvoke(settings, scope, action, input)\n context db = scope\n schema = schemaName(settings.application)\n if action == \"job\"\n single = SQL\n select id::text, name as queue, data->>'path' as path, state::text,\n retry_count as \"retryCount\", retry_limit as \"retryLimit\",\n to_char(created_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"createdAt\",\n to_char(start_after at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startAfter\",\n to_char(started_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startedAt\",\n to_char(completed_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"completedAt\",\n data->'input' as input, data->'source' as source, output\n from ${schema}.job\n where id = :id::uuid and data->>'application' = :application\n and data->'version' = '1'::jsonb\n limit 2\n single.id = input.id\n single.application = settings.application\n single.execute()\n if !single.next()\n return null\n result = summary(single)\n result.input = single.input\n result.source = single.source\n result.output = single.output\n if single.next()\n return null\n return result\n listing = SQL\n select id::text, name as queue, data->>'path' as path, state::text,\n retry_count as \"retryCount\", retry_limit as \"retryLimit\",\n to_char(created_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"createdAt\",\n to_char(start_after at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startAfter\",\n to_char(started_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"startedAt\",\n to_char(completed_on at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS.US\"Z\"') as \"completedAt\"\n from ${schema}.job\n where data->>'application' = :application and data->'version' = '1'::jsonb\n and (:queue::text is null or name = :queue)\n and (:path::text is null or data->>'path' = :path)\n and (:state::text is null or state::text = :state)\n and (:cursorTime::timestamptz is null or (created_on, id, name) < (:cursorTime::timestamptz, :cursorId::uuid, :cursorQueue::text))\n order by created_on desc, id desc, name desc\n limit :limit\n listing.application = settings.application\n listing.queue = input.queue\n listing.path = input.path\n listing.state = input.state\n listing.limit = input.limit\n listing.cursorTime = null\n listing.cursorId = null\n listing.cursorQueue = null\n if input.position != null\n listing.cursorTime = input.position.createdAt\n listing.cursorId = input.position.id\n listing.cursorQueue = input.position.name\n listing.execute()\n rows = []\n loop while listing.next()\n rows.add(summary(listing))\n return rows\n\nreadJob(settings, db, token, id, management = false)\n usable(db)\n if management\n manager(token)\n if !uuid(id)\n return null\n row = invoke(settings, db, \"job\", {\n id: id\n })\n if row == null\n return null\n if !management and (!owned(row.source, token) or !permitted(settings, row.path, row.queue, token))\n return null\n result = summary(row)\n result.resultAvailable = false\n result.result = null\n result.error = null\n output = row.output\n if output != null and is_object(output) and !is_array(output) and output.version == 1\n if row.state == \"completed\" and Object/hasOwn(output, \"value\")\n result.resultAvailable = true\n result.result = output.value\n if row.state == \"failed\" and output.error != null and is_object(output.error)\n if is_string(output.error.code) and is_bool(output.error.permanent)\n result.error = {\n code: output.error.code\n permanent: output.error.permanent\n }\n if management\n result.input = row.input\n result.source = safeSource(row.source)\n return result\n\nsafeSource(source)\n result = {}\n if source == null or !is_object(source) or is_array(source)\n return null\n for [\"kind\", \"clientId\", \"userId\", \"grantId\", \"identity\"] as field\n if is_string(source[field])\n result[field] = source[field]\n return result\n\nsummary(row)\n return {\n id: row.id\n queue: row.queue\n path: row.path\n state: row.state\n retryCount: row.retryCount\n retryLimit: row.retryLimit\n createdAt: row.createdAt\n startAfter: row.startAfter\n startedAt: row.startedAt\n completedAt: row.completedAt\n }\n\nfilters(options)\n if options == null\n options = {}\n if !is_object(options) or is_array(options)\n throw \"Job list options must be a map\"\n allowed = [\"queue\", \"path\", \"state\", \"limit\", \"cursor\"]\n for options as key: value\n if !allowed.includes(key)\n throw \"Unknown job list option: ${key}\"\n result = {\n queue: null\n path: null\n state: null\n limit: 50\n cursor: null\n }\n for [\"queue\", \"path\", \"state\"] as field\n value = options[field]\n if value != null\n if !is_string(value) or value == \"\" or value.length > 2048\n throw \"Invalid job list filter: ${field}\"\n result[field] = value\n states = [\"created\", \"retry\", \"active\", \"completed\", \"cancelled\", \"failed\"]\n if result.state != null and !states.includes(result.state)\n throw \"Invalid job state filter\"\n if options.limit != null\n if !Number/isSafeInteger(options.limit) or options.limit < 1 or options.limit > 200\n throw \"Job list limit must be between 1 and 200\"\n result.limit = options.limit\n if options.cursor != null\n if !is_string(options.cursor) or options.cursor.length == 0 or options.cursor.length > 8192\n throw \"Invalid job cursor\"\n result.cursor = options.cursor\n return result\n\ndecodeCursor(settings, selected)\n if selected.cursor == null\n return null\n try\n bytes = Buffer/from(selected.cursor, \"base64url\")\n if bytes.toString(\"base64url\") != selected.cursor\n throw \"Invalid encoding\"\n value = from_json(bytes.toString(\"utf8\"))\n if value == null or !is_object(value) or is_array(value)\n throw \"Invalid cursor\"\n if value.version != 1 or value.application != settings.application\n throw \"Wrong cursor scope\"\n for [\"queue\", \"path\", \"state\"] as field\n if !Object/hasOwn(value, field) or value[field] != selected[field]\n throw \"Changed cursor filters\"\n pattern = new RegExp(\"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\\\.[0-9]{6}Z$\")\n if !is_string(value.createdAt) or !pattern.test(value.createdAt) or !uuid(value.id) or !is_string(value.name)\n throw \"Invalid cursor position\"\n stamp = Date/parse(value.createdAt)\n if !Number/isFinite(stamp)\n throw \"Invalid cursor time\"\n date = new Date(stamp)\n if date.toISOString() != \"${value.createdAt.slice(0, 23)}Z\"\n throw \"Invalid cursor time\"\n if value.name.length == 0 or value.name.length > 200\n throw \"Invalid cursor queue\"\n return value\n catch error\n throw \"Invalid job cursor\"\n\nencodeCursor(settings, selected, row)\n return Buffer/from(to_json({\n version: 1\n application: settings.application\n queue: selected.queue\n path: selected.path\n state: selected.state\n createdAt: row.createdAt\n id: row.id\n name: row.queue\n }), \"utf8\").toString(\"base64url\")\n\nreadJobs(settings, db, token, options)\n usable(db)\n manager(token)\n selected = filters(options)\n cursor = decodeCursor(settings, selected)\n rows = invoke(settings, db, \"jobs\", {\n queue: selected.queue\n path: selected.path\n state: selected.state\n limit: selected.limit + 1\n position: cursor\n })\n items = []\n last = null\n for rows as row\n if items.length == selected.limit\n break\n items.add(summary(row))\n last = row\n next = null\n if rows.length > selected.limit\n next = encodeCursor(settings, selected, last)\n return {\n items: items\n nextCursor: next\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;AAMA;;;;;;;;;;AAKA;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;AASA;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"28054511688baedacb80fd485fb6aa22af089177689f569867534f31b7aaff56","outputHash":"0e933bdc55055553133e89957702df292a98fb9f2978ac6e38f2b53d130cfbe3","mapHash":"915a26153f9d8b49f30046bdaae636a31fbf35c5a7f0439a0e5317614379fd56"}}