@flowcore/data-pump 0.1.11 → 0.2.0
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.
- package/CHANGELOG.md +12 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.d.ts +25 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.d.ts.map +1 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.js +201 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.d.ts +51 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.d.ts.map +1 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.js +131 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.d.ts +3 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.js +2 -0
- package/esm/lib/data-pump.d.ts.map +1 -1
- package/esm/lib/data-pump.js +8 -7
- package/esm/mod.d.ts +0 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +0 -1
- package/package.json +2 -2
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.d.ts +25 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.d.ts.map +1 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/time-uuid.js +230 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.d.ts +51 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.d.ts.map +1 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.js +157 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.d.ts +3 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.js +18 -0
- package/script/lib/data-pump.d.ts.map +1 -1
- package/script/lib/data-pump.js +10 -9
- package/script/mod.d.ts +0 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +0 -1
- package/esm/lib/time-uuid.d.ts +0 -15
- package/esm/lib/time-uuid.d.ts.map +0 -1
- package/esm/lib/time-uuid.js +0 -43
- package/script/lib/time-uuid.d.ts +0 -15
- package/script/lib/time-uuid.d.ts.map +0 -1
- package/script/lib/time-uuid.js +0 -47
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright DataStax, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
"use strict";
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.TimeUuid = void 0;
|
|
45
|
+
const crypto = __importStar(require("node:crypto"));
|
|
46
|
+
const long_1 = __importDefault(require("long"));
|
|
47
|
+
const node_buffer_1 = require("node:buffer");
|
|
48
|
+
const uuid_js_1 = require("./uuid.js");
|
|
49
|
+
/** @module types */
|
|
50
|
+
/**
|
|
51
|
+
* Oct 15, 1582 in milliseconds since unix epoch
|
|
52
|
+
* @const
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
const _unixToGregorian = 12219292800000;
|
|
56
|
+
/**
|
|
57
|
+
* 10,000 ticks in a millisecond
|
|
58
|
+
* @const
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
const _ticksInMs = 10000;
|
|
62
|
+
const minNodeId = node_buffer_1.Buffer.from("808080808080", "hex");
|
|
63
|
+
const minClockId = node_buffer_1.Buffer.from("8080", "hex");
|
|
64
|
+
const maxNodeId = node_buffer_1.Buffer.from("7f7f7f7f7f7f", "hex");
|
|
65
|
+
const maxClockId = node_buffer_1.Buffer.from("7f7f", "hex");
|
|
66
|
+
/**
|
|
67
|
+
* Counter used to generate up to 10000 different timeuuid values with the same Date
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
let _ticks = 0;
|
|
71
|
+
/**
|
|
72
|
+
* Counter used to generate ticks for the current time
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
let _ticksForCurrentTime = 0;
|
|
76
|
+
/**
|
|
77
|
+
* Remember the last time when a ticks for the current time so that it can be reset
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
let _lastTimestamp = 0;
|
|
81
|
+
class TimeUuid extends uuid_js_1.Uuid {
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new instance of TimeUuid based on the parameters provided according to rfc4122.
|
|
84
|
+
*/
|
|
85
|
+
constructor(value, ticks, nodeId, clockId) {
|
|
86
|
+
let buffer;
|
|
87
|
+
if (value instanceof node_buffer_1.Buffer) {
|
|
88
|
+
if (value.length !== 16) {
|
|
89
|
+
throw new Error("Buffer for v1 uuid not valid");
|
|
90
|
+
}
|
|
91
|
+
buffer = value;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
buffer = generateBuffer(value, ticks, nodeId, clockId);
|
|
95
|
+
}
|
|
96
|
+
super(buffer);
|
|
97
|
+
}
|
|
98
|
+
static fromDate(date, ticks, nodeId, clockId) {
|
|
99
|
+
return new TimeUuid(date, ticks, nodeId, clockId);
|
|
100
|
+
}
|
|
101
|
+
static fromString(value) {
|
|
102
|
+
return new TimeUuid(uuid_js_1.Uuid.fromString(value).getBuffer());
|
|
103
|
+
}
|
|
104
|
+
static min(date, ticks) {
|
|
105
|
+
return new TimeUuid(date, ticks, minNodeId, minClockId);
|
|
106
|
+
}
|
|
107
|
+
static max(date, ticks) {
|
|
108
|
+
return new TimeUuid(date, ticks, maxNodeId, maxClockId);
|
|
109
|
+
}
|
|
110
|
+
static now(nodeId, clockId) {
|
|
111
|
+
return TimeUuid.fromDate(undefined, undefined, nodeId, clockId);
|
|
112
|
+
}
|
|
113
|
+
getDatePrecision() {
|
|
114
|
+
const timeLow = this.buffer.readUInt32BE(0);
|
|
115
|
+
let timeHigh = 0;
|
|
116
|
+
timeHigh |= (this.buffer[4] & 0xff) << 8;
|
|
117
|
+
timeHigh |= this.buffer[5] & 0xff;
|
|
118
|
+
timeHigh |= (this.buffer[6] & 0x0f) << 24;
|
|
119
|
+
timeHigh |= (this.buffer[7] & 0xff) << 16;
|
|
120
|
+
const val = long_1.default.fromBits(timeLow, timeHigh);
|
|
121
|
+
const ticksInMsLong = long_1.default.fromNumber(_ticksInMs);
|
|
122
|
+
const ticks = val.modulo(ticksInMsLong);
|
|
123
|
+
const time = val
|
|
124
|
+
.div(ticksInMsLong)
|
|
125
|
+
.subtract(long_1.default.fromNumber(_unixToGregorian));
|
|
126
|
+
return {
|
|
127
|
+
date: new Date(time.toNumber()),
|
|
128
|
+
ticks: ticks.toNumber(),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
getDate() {
|
|
132
|
+
return this.getDatePrecision().date;
|
|
133
|
+
}
|
|
134
|
+
getNodeId() {
|
|
135
|
+
return this.buffer.subarray(10);
|
|
136
|
+
}
|
|
137
|
+
getClockId() {
|
|
138
|
+
return this.buffer.subarray(8, 10);
|
|
139
|
+
}
|
|
140
|
+
getNodeIdString() {
|
|
141
|
+
return this.buffer.subarray(10).toString("ascii");
|
|
142
|
+
}
|
|
143
|
+
getBefore() {
|
|
144
|
+
const { date: beforeDate, ticks } = this.getDatePrecision();
|
|
145
|
+
return TimeUuid.fromDate(beforeDate, ticks - 1, this.getNodeId(), this.getClockId());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.TimeUuid = TimeUuid;
|
|
149
|
+
// Helper functions
|
|
150
|
+
function writeTime(buffer, time, ticks) {
|
|
151
|
+
const val = long_1.default
|
|
152
|
+
.fromNumber(time + _unixToGregorian)
|
|
153
|
+
.multiply(long_1.default.fromNumber(10000))
|
|
154
|
+
.add(long_1.default.fromNumber(ticks));
|
|
155
|
+
const timeHigh = val.getHighBitsUnsigned();
|
|
156
|
+
buffer.writeUInt32BE(val.getLowBitsUnsigned(), 0);
|
|
157
|
+
buffer.writeUInt16BE(timeHigh & 0xffff, 4);
|
|
158
|
+
buffer.writeUInt16BE(timeHigh >>> 16 & 0xffff, 6);
|
|
159
|
+
}
|
|
160
|
+
function getClockId(clockId) {
|
|
161
|
+
let buffer = clockId;
|
|
162
|
+
if (typeof clockId === "string") {
|
|
163
|
+
buffer = node_buffer_1.Buffer.from(clockId, "ascii");
|
|
164
|
+
}
|
|
165
|
+
if (!(buffer instanceof node_buffer_1.Buffer)) {
|
|
166
|
+
buffer = getRandomBytes(2);
|
|
167
|
+
}
|
|
168
|
+
else if (buffer.length !== 2) {
|
|
169
|
+
throw new Error("Clock identifier must have 2 bytes");
|
|
170
|
+
}
|
|
171
|
+
return buffer;
|
|
172
|
+
}
|
|
173
|
+
function getNodeId(nodeId) {
|
|
174
|
+
let buffer = nodeId;
|
|
175
|
+
if (typeof nodeId === "string") {
|
|
176
|
+
buffer = node_buffer_1.Buffer.from(nodeId, "ascii");
|
|
177
|
+
}
|
|
178
|
+
if (!(buffer instanceof node_buffer_1.Buffer)) {
|
|
179
|
+
buffer = getRandomBytes(6);
|
|
180
|
+
}
|
|
181
|
+
else if (buffer.length !== 6) {
|
|
182
|
+
throw new Error("Node identifier must have 6 bytes");
|
|
183
|
+
}
|
|
184
|
+
return buffer;
|
|
185
|
+
}
|
|
186
|
+
function getTicks(ticks) {
|
|
187
|
+
if (typeof ticks !== "number" || ticks >= _ticksInMs) {
|
|
188
|
+
_ticks++;
|
|
189
|
+
if (_ticks >= _ticksInMs) {
|
|
190
|
+
_ticks = 0;
|
|
191
|
+
}
|
|
192
|
+
ticks = _ticks;
|
|
193
|
+
}
|
|
194
|
+
return ticks;
|
|
195
|
+
}
|
|
196
|
+
function getTimeWithTicks(date, ticks) {
|
|
197
|
+
if (!(date instanceof Date) || isNaN(date.getTime())) {
|
|
198
|
+
date = new Date();
|
|
199
|
+
const time = date.getTime();
|
|
200
|
+
_ticksForCurrentTime++;
|
|
201
|
+
if (_ticksForCurrentTime > _ticksInMs || time > _lastTimestamp) {
|
|
202
|
+
_ticksForCurrentTime = 0;
|
|
203
|
+
_lastTimestamp = time;
|
|
204
|
+
}
|
|
205
|
+
ticks = _ticksForCurrentTime;
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
time: date.getTime(),
|
|
209
|
+
ticks: getTicks(ticks),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function getRandomBytes(length) {
|
|
213
|
+
return crypto.randomBytes(length);
|
|
214
|
+
}
|
|
215
|
+
function generateBuffer(date, ticks, nodeId, clockId) {
|
|
216
|
+
const timeWithTicks = getTimeWithTicks(date, ticks);
|
|
217
|
+
const nodeBuffer = getNodeId(nodeId);
|
|
218
|
+
const clockBuffer = getClockId(clockId);
|
|
219
|
+
const buffer = node_buffer_1.Buffer.alloc(16);
|
|
220
|
+
writeTime(buffer, timeWithTicks.time, timeWithTicks.ticks);
|
|
221
|
+
clockBuffer.copy(buffer, 8, 0);
|
|
222
|
+
nodeBuffer.copy(buffer, 10, 0);
|
|
223
|
+
// Version Byte: Time based
|
|
224
|
+
buffer[6] = buffer[6] & 0x0f;
|
|
225
|
+
buffer[6] = buffer[6] | 0x10;
|
|
226
|
+
// IETF Variant Byte
|
|
227
|
+
buffer[8] = buffer[8] & 0x3f;
|
|
228
|
+
buffer[8] = buffer[8] | 0x80;
|
|
229
|
+
return buffer;
|
|
230
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
/** @module types */
|
|
3
|
+
/**
|
|
4
|
+
* Represents an immutable universally unique identifier (UUID).
|
|
5
|
+
* A UUID represents a 128-bit value.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Uuid {
|
|
8
|
+
protected buffer: Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new instance of Uuid based on a Buffer
|
|
11
|
+
* @param buffer The 16-length buffer.
|
|
12
|
+
*/
|
|
13
|
+
constructor(buffer: Buffer);
|
|
14
|
+
/**
|
|
15
|
+
* Parses a string representation of a Uuid
|
|
16
|
+
* @param value The string representation of UUID
|
|
17
|
+
* @returns A new Uuid instance
|
|
18
|
+
*/
|
|
19
|
+
static fromString(value: string): Uuid;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new random (version 4) Uuid.
|
|
22
|
+
*/
|
|
23
|
+
static random(): Uuid;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the bytes representation of a Uuid
|
|
26
|
+
* @returns The buffer containing the bytes
|
|
27
|
+
*/
|
|
28
|
+
getBuffer(): Buffer;
|
|
29
|
+
/**
|
|
30
|
+
* Compares this object to the specified object.
|
|
31
|
+
* The result is true if and only if the argument is not null, is a UUID object,
|
|
32
|
+
* and contains the same value, bit for bit, as this UUID.
|
|
33
|
+
* @param other The other value to test for equality.
|
|
34
|
+
*/
|
|
35
|
+
equals(other: Uuid): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a string representation of the value of this Uuid instance.
|
|
38
|
+
* 32 hex separated by hyphens, in the form of 00000000-0000-0000-0000-000000000000.
|
|
39
|
+
*/
|
|
40
|
+
toString(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Provide the name of the constructor and the string representation
|
|
43
|
+
*/
|
|
44
|
+
inspect(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the string representation.
|
|
47
|
+
* Method used by the native JSON.stringify() to serialize this instance.
|
|
48
|
+
*/
|
|
49
|
+
toJSON(): string;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/lib/uuid.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,oBAAoB;AAEpB;;;GAGG;AACH,qBAAa,IAAI;IACf,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAO1B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQtC;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,IAAI;IAKrB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO;IAI5B;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAYlB;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;;OAGG;IACH,MAAM,IAAI,MAAM;CAGjB"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright DataStax, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
"use strict";
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.Uuid = void 0;
|
|
42
|
+
const crypto = __importStar(require("node:crypto"));
|
|
43
|
+
const node_buffer_1 = require("node:buffer");
|
|
44
|
+
/** @module types */
|
|
45
|
+
/**
|
|
46
|
+
* Represents an immutable universally unique identifier (UUID).
|
|
47
|
+
* A UUID represents a 128-bit value.
|
|
48
|
+
*/
|
|
49
|
+
class Uuid {
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new instance of Uuid based on a Buffer
|
|
52
|
+
* @param buffer The 16-length buffer.
|
|
53
|
+
*/
|
|
54
|
+
constructor(buffer) {
|
|
55
|
+
Object.defineProperty(this, "buffer", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
if (!buffer || buffer.length !== 16) {
|
|
62
|
+
throw new Error("You must provide a buffer containing 16 bytes");
|
|
63
|
+
}
|
|
64
|
+
this.buffer = buffer;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parses a string representation of a Uuid
|
|
68
|
+
* @param value The string representation of UUID
|
|
69
|
+
* @returns A new Uuid instance
|
|
70
|
+
*/
|
|
71
|
+
static fromString(value) {
|
|
72
|
+
//36 chars: 32 + 4 hyphens
|
|
73
|
+
if (typeof value !== "string" || value.length !== 36) {
|
|
74
|
+
throw new Error("Invalid string representation of Uuid, it should be in the 00000000-0000-0000-0000-000000000000");
|
|
75
|
+
}
|
|
76
|
+
return new Uuid(node_buffer_1.Buffer.from(value.replace(/-/g, ""), "hex"));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new random (version 4) Uuid.
|
|
80
|
+
*/
|
|
81
|
+
static random() {
|
|
82
|
+
const buffer = getRandomBytes();
|
|
83
|
+
return createUuidFromBuffer(buffer);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the bytes representation of a Uuid
|
|
87
|
+
* @returns The buffer containing the bytes
|
|
88
|
+
*/
|
|
89
|
+
getBuffer() {
|
|
90
|
+
return this.buffer;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compares this object to the specified object.
|
|
94
|
+
* The result is true if and only if the argument is not null, is a UUID object,
|
|
95
|
+
* and contains the same value, bit for bit, as this UUID.
|
|
96
|
+
* @param other The other value to test for equality.
|
|
97
|
+
*/
|
|
98
|
+
equals(other) {
|
|
99
|
+
return other instanceof Uuid && this.buffer.equals(other.buffer);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns a string representation of the value of this Uuid instance.
|
|
103
|
+
* 32 hex separated by hyphens, in the form of 00000000-0000-0000-0000-000000000000.
|
|
104
|
+
*/
|
|
105
|
+
toString() {
|
|
106
|
+
//32 hex representation of the Buffer
|
|
107
|
+
const hexValue = getHex(this);
|
|
108
|
+
return (hexValue.substr(0, 8) + "-" +
|
|
109
|
+
hexValue.substr(8, 4) + "-" +
|
|
110
|
+
hexValue.substr(12, 4) + "-" +
|
|
111
|
+
hexValue.substr(16, 4) + "-" +
|
|
112
|
+
hexValue.substr(20, 12));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Provide the name of the constructor and the string representation
|
|
116
|
+
*/
|
|
117
|
+
inspect() {
|
|
118
|
+
return this.constructor.name + ": " + this.toString();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns the string representation.
|
|
122
|
+
* Method used by the native JSON.stringify() to serialize this instance.
|
|
123
|
+
*/
|
|
124
|
+
toJSON() {
|
|
125
|
+
return this.toString();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Uuid = Uuid;
|
|
129
|
+
/**
|
|
130
|
+
* Returns new Uuid
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
function createUuidFromBuffer(buffer) {
|
|
134
|
+
//clear the version
|
|
135
|
+
buffer[6] &= 0x0f;
|
|
136
|
+
//set the version 4
|
|
137
|
+
buffer[6] |= 0x40;
|
|
138
|
+
//clear the variant
|
|
139
|
+
buffer[8] &= 0x3f;
|
|
140
|
+
//set the IETF variant
|
|
141
|
+
buffer[8] |= 0x80;
|
|
142
|
+
return new Uuid(buffer);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @private
|
|
146
|
+
* @returns 32 hex representation of the instance, without separators
|
|
147
|
+
*/
|
|
148
|
+
function getHex(uuid) {
|
|
149
|
+
return uuid.getBuffer().toString("hex");
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Gets a crypto generated 16 bytes
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
function getRandomBytes() {
|
|
156
|
+
return crypto.randomBytes(16);
|
|
157
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lib/time-uuid.js"), exports);
|
|
18
|
+
__exportStar(require("./lib/uuid.js"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-pump.d.ts","sourceRoot":"","sources":["../../src/lib/data-pump.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAEnB,MAAM,iDAAiD,CAAA;AAiBxD,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,C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0;
|
|
4
4
|
const mod_js_1 = require("../deps/jsr.io/@flowcore/sdk/1.11.10/src/mod.js");
|
|
5
|
-
const
|
|
5
|
+
const mod_js_2 = require("../deps/jsr.io/@flowcore/time-uuid/0.1.1/src/mod.js");
|
|
6
6
|
const date_fns_1 = require("date-fns");
|
|
7
7
|
const utc_1 = require("@date-fns/utc");
|
|
8
8
|
var FlowcoreBufferEventStatus;
|
|
@@ -91,7 +91,7 @@ class DataPump {
|
|
|
91
91
|
if (this.options.stopAt) {
|
|
92
92
|
const timeBucket = (0, date_fns_1.format)((0, date_fns_1.startOfHour)((0, utc_1.utc)(this.options.stopAt)), "yyyyMMddHH0000");
|
|
93
93
|
const lastTimeBucket = this.getClosestTimeBucket(timeBucket, true);
|
|
94
|
-
const lastEventId =
|
|
94
|
+
const lastEventId = mod_js_2.TimeUuid.fromDate(this.options.stopAt).toString();
|
|
95
95
|
this.stopAt = {
|
|
96
96
|
timeBucket: lastTimeBucket,
|
|
97
97
|
eventId: lastEventId,
|
|
@@ -102,7 +102,7 @@ class DataPump {
|
|
|
102
102
|
const newState = await this.options.stateManager.getState();
|
|
103
103
|
if (!newState) {
|
|
104
104
|
this.state.timeBucket = this.getClosestTimeBucket(this.getNowTimeBucket());
|
|
105
|
-
this.state.eventId =
|
|
105
|
+
this.state.eventId = mod_js_2.TimeUuid.now().toString();
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
this.state.timeBucket = this.getClosestTimeBucket(newState.timeBucket);
|
|
@@ -176,7 +176,7 @@ class DataPump {
|
|
|
176
176
|
}
|
|
177
177
|
// How many events should we fetch
|
|
178
178
|
const eventsToFetch = this.options.buffer.size - this.buffer.length;
|
|
179
|
-
this.logger?.
|
|
179
|
+
this.logger?.info(`fetching events from ${this.state.timeBucket} @ ${this.state.eventId ?? "-"}`);
|
|
180
180
|
const timeStart = Date.now();
|
|
181
181
|
const command = new mod_js_1.EventsFetchCommand({
|
|
182
182
|
tenant: this.options.dataSource.tenant,
|
|
@@ -204,7 +204,7 @@ class DataPump {
|
|
|
204
204
|
this.buffer.push(...events);
|
|
205
205
|
// Check if we have a waiter and if we have events, notify the waiter
|
|
206
206
|
events.length && this.waiter?.();
|
|
207
|
-
this.logger?.
|
|
207
|
+
this.logger?.info(`Got ${result.events.length} events from ${this.state.timeBucket} @ ${this.state.eventId ?? "-"} in ${time}ms. Buffer size ${this.buffer.length}`);
|
|
208
208
|
// Update buffer state
|
|
209
209
|
this.state.eventId = result.events[result.events.length - 1]?.eventId ?? this.state.eventId;
|
|
210
210
|
// If we don't have a next cursor move to next time bucket
|
|
@@ -272,12 +272,13 @@ class DataPump {
|
|
|
272
272
|
const firstEvent = this.buffer[0];
|
|
273
273
|
if (!firstEvent) {
|
|
274
274
|
if (eventId) {
|
|
275
|
-
const
|
|
276
|
-
|
|
275
|
+
const date = mod_js_2.TimeUuid.fromString(eventId).getDate();
|
|
276
|
+
const timeBucket = (0, date_fns_1.format)((0, date_fns_1.startOfHour)((0, utc_1.utc)(date)), "yyyyMMddHH0000");
|
|
277
|
+
return this.options.stateManager.setState?.({ timeBucket, eventId });
|
|
277
278
|
}
|
|
278
279
|
return;
|
|
279
280
|
}
|
|
280
|
-
const timeUuid =
|
|
281
|
+
const timeUuid = mod_js_2.TimeUuid.fromString(firstEvent.event.eventId);
|
|
281
282
|
const timeBucket = firstEvent.event.timeBucket;
|
|
282
283
|
return this.options.stateManager.setState?.({ timeBucket, eventId: timeUuid.getBefore().toString() });
|
|
283
284
|
}
|
|
@@ -379,7 +380,7 @@ class DataPump {
|
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
382
|
async waitForNotifier() {
|
|
382
|
-
this.logger?.
|
|
383
|
+
this.logger?.info("No more events, waiting for notifier...");
|
|
383
384
|
this.notifierAbortController = new AbortController();
|
|
384
385
|
await this.options.notifier.wait({ ...this.options.dataSource, dataCoreId: await this.getDataCoreId() }, this.notifierAbortController.signal);
|
|
385
386
|
this.notifierAbortController = undefined;
|
package/script/mod.d.ts
CHANGED
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,2BAA2B,CAAA"}
|
package/script/mod.js
CHANGED
|
@@ -17,4 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
require("./_dnt.polyfills.js");
|
|
18
18
|
__exportStar(require("./lib/data-pump.js"), exports);
|
|
19
19
|
__exportStar(require("./lib/data-pump-create.js"), exports);
|
|
20
|
-
__exportStar(require("./lib/time-uuid.js"), exports);
|
package/esm/lib/time-uuid.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Buffer } from "node:buffer";
|
|
2
|
-
import { types } from "cassandra-driver";
|
|
3
|
-
export declare class TimeUuid {
|
|
4
|
-
private readonly timeUuid;
|
|
5
|
-
constructor(timeUuid: types.TimeUuid);
|
|
6
|
-
static fromDate(date: Date, ticks?: number, nodeId?: string | Buffer, clockId?: string | Buffer): TimeUuid;
|
|
7
|
-
static fromString(value: string): TimeUuid;
|
|
8
|
-
private getDatePrecision;
|
|
9
|
-
getBefore(): TimeUuid;
|
|
10
|
-
static fromNow(): TimeUuid;
|
|
11
|
-
toString(): string;
|
|
12
|
-
getTimeBucket(): string;
|
|
13
|
-
getDate(): Date;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=time-uuid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time-uuid.d.ts","sourceRoot":"","sources":["../../src/lib/time-uuid.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAGxC,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,KAAK,CAAC,QAAQ;WAEvC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ;WAInG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ;IAIjD,OAAO,CAAC,gBAAgB;IAIjB,SAAS,IAAI,QAAQ;WASd,OAAO,IAAI,QAAQ;IAI1B,QAAQ,IAAI,MAAM;IAIlB,aAAa,IAAI,MAAM;IAIvB,OAAO,IAAI,IAAI;CAGvB"}
|
package/esm/lib/time-uuid.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { subMilliseconds } from "date-fns";
|
|
2
|
-
import { utc } from "@date-fns/utc";
|
|
3
|
-
import { types } from "cassandra-driver";
|
|
4
|
-
import { format, startOfHour } from "date-fns";
|
|
5
|
-
export class TimeUuid {
|
|
6
|
-
constructor(timeUuid) {
|
|
7
|
-
Object.defineProperty(this, "timeUuid", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: timeUuid
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
static fromDate(date, ticks, nodeId, clockId) {
|
|
15
|
-
return new TimeUuid(types.TimeUuid.fromDate(utc(date), ticks, nodeId, clockId));
|
|
16
|
-
}
|
|
17
|
-
static fromString(value) {
|
|
18
|
-
return new TimeUuid(types.TimeUuid.fromString(value));
|
|
19
|
-
}
|
|
20
|
-
getDatePrecision() {
|
|
21
|
-
return this.timeUuid.getDatePrecision();
|
|
22
|
-
}
|
|
23
|
-
getBefore() {
|
|
24
|
-
const { date, ticks } = this.getDatePrecision();
|
|
25
|
-
const newTicks = ticks - 1;
|
|
26
|
-
if (newTicks < 0) {
|
|
27
|
-
return TimeUuid.fromDate(subMilliseconds(date, 1), 10_000);
|
|
28
|
-
}
|
|
29
|
-
return TimeUuid.fromDate(date, newTicks);
|
|
30
|
-
}
|
|
31
|
-
static fromNow() {
|
|
32
|
-
return TimeUuid.fromDate(new Date(), 10_000);
|
|
33
|
-
}
|
|
34
|
-
toString() {
|
|
35
|
-
return this.timeUuid.toString();
|
|
36
|
-
}
|
|
37
|
-
getTimeBucket() {
|
|
38
|
-
return format(startOfHour(this.timeUuid.getDate()), "yyyyMMddHH0000");
|
|
39
|
-
}
|
|
40
|
-
getDate() {
|
|
41
|
-
return this.timeUuid.getDate();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Buffer } from "node:buffer";
|
|
2
|
-
import { types } from "cassandra-driver";
|
|
3
|
-
export declare class TimeUuid {
|
|
4
|
-
private readonly timeUuid;
|
|
5
|
-
constructor(timeUuid: types.TimeUuid);
|
|
6
|
-
static fromDate(date: Date, ticks?: number, nodeId?: string | Buffer, clockId?: string | Buffer): TimeUuid;
|
|
7
|
-
static fromString(value: string): TimeUuid;
|
|
8
|
-
private getDatePrecision;
|
|
9
|
-
getBefore(): TimeUuid;
|
|
10
|
-
static fromNow(): TimeUuid;
|
|
11
|
-
toString(): string;
|
|
12
|
-
getTimeBucket(): string;
|
|
13
|
-
getDate(): Date;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=time-uuid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time-uuid.d.ts","sourceRoot":"","sources":["../../src/lib/time-uuid.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAGxC,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,KAAK,CAAC,QAAQ;WAEvC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ;WAInG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ;IAIjD,OAAO,CAAC,gBAAgB;IAIjB,SAAS,IAAI,QAAQ;WASd,OAAO,IAAI,QAAQ;IAI1B,QAAQ,IAAI,MAAM;IAIlB,aAAa,IAAI,MAAM;IAIvB,OAAO,IAAI,IAAI;CAGvB"}
|