Initial commit: notification-elements-demo app

Interactive Angular 19 demo for @sda/notification-elements-ui with
6 sections: Bell & Feed, Notification Center, Inbox, Comments &
Threads, Mention Input, and Full-Featured layout. Includes mock
data, dark mode toggle, and real-time event log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Giuliano Silvestro
2026-02-13 21:49:19 +10:00
commit 5d0c9ec7eb
36473 changed files with 3778146 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { JsonDecoder } from '../json/JsonDecoder';
export interface EjsonDecoderOptions {
legacy?: boolean;
}
export declare class EjsonDecoder extends JsonDecoder {
private options;
constructor(options?: EjsonDecoderOptions);
decodeFromString(json: string): unknown;
readAny(): unknown;
readArr(): unknown[];
readObjWithEjsonSupport(): unknown;
private readValue;
private readRawObj;
private transformEjsonObject;
private parseObjectId;
private base64ToUint8Array;
private isValidUuid;
private uuidToBytes;
}

View File

@@ -0,0 +1,449 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EjsonDecoder = void 0;
const values_1 = require("../bson/values");
const JsonDecoder_1 = require("../json/JsonDecoder");
const JsonDecoder_2 = require("../json/JsonDecoder");
class EjsonDecoder extends JsonDecoder_1.JsonDecoder {
constructor(options = {}) {
super();
this.options = options;
}
decodeFromString(json) {
const bytes = new TextEncoder().encode(json);
return this.decode(bytes);
}
readAny() {
this.skipWhitespace();
const reader = this.reader;
const uint8 = reader.uint8;
const char = uint8[reader.x];
switch (char) {
case 34:
return this.readStr();
case 91:
return this.readArr();
case 102:
return this.readFalse();
case 110:
return this.readNull();
case 116:
return this.readTrue();
case 123:
return this.readObjWithEjsonSupport();
default:
if ((char >= 48 && char <= 57) || char === 45)
return this.readNum();
throw new Error('Invalid JSON');
}
}
readArr() {
const reader = this.reader;
if (reader.u8() !== 0x5b)
throw new Error('Invalid JSON');
const arr = [];
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
const char = uint8[reader.x];
if (char === 0x5d)
return reader.x++, arr;
if (char === 0x2c)
reader.x++;
else if (!first)
throw new Error('Invalid JSON');
this.skipWhitespace();
arr.push(this.readAny());
first = false;
}
}
readObjWithEjsonSupport() {
const reader = this.reader;
if (reader.u8() !== 0x7b)
throw new Error('Invalid JSON');
const obj = {};
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
let char = uint8[reader.x];
if (char === 0x7d) {
reader.x++;
return this.transformEjsonObject(obj);
}
if (char === 0x2c)
reader.x++;
else if (!first)
throw new Error('Invalid JSON');
this.skipWhitespace();
char = uint8[reader.x++];
if (char !== 0x22)
throw new Error('Invalid JSON');
const key = (0, JsonDecoder_2.readKey)(reader);
if (key === '__proto__')
throw new Error('Invalid JSON');
this.skipWhitespace();
if (reader.u8() !== 0x3a)
throw new Error('Invalid JSON');
this.skipWhitespace();
obj[key] = this.readValue();
first = false;
}
}
readValue() {
this.skipWhitespace();
const reader = this.reader;
const uint8 = reader.uint8;
const char = uint8[reader.x];
switch (char) {
case 34:
return this.readStr();
case 91:
return this.readArr();
case 102:
return this.readFalse();
case 110:
return this.readNull();
case 116:
return this.readTrue();
case 123:
return this.readRawObj();
default:
if ((char >= 48 && char <= 57) || char === 45)
return this.readNum();
throw new Error('Invalid JSON');
}
}
readRawObj() {
const reader = this.reader;
if (reader.u8() !== 0x7b)
throw new Error('Invalid JSON');
const obj = {};
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
let char = uint8[reader.x];
if (char === 0x7d) {
reader.x++;
return obj;
}
if (char === 0x2c)
reader.x++;
else if (!first)
throw new Error('Invalid JSON');
this.skipWhitespace();
char = uint8[reader.x++];
if (char !== 0x22)
throw new Error('Invalid JSON');
const key = (0, JsonDecoder_2.readKey)(reader);
if (key === '__proto__')
throw new Error('Invalid JSON');
this.skipWhitespace();
if (reader.u8() !== 0x3a)
throw new Error('Invalid JSON');
this.skipWhitespace();
obj[key] = this.readValue();
first = false;
}
}
transformEjsonObject(obj) {
const keys = Object.keys(obj);
const hasExactKeys = (expectedKeys) => {
if (keys.length !== expectedKeys.length)
return false;
return expectedKeys.every((key) => keys.includes(key));
};
const specialKeys = keys.filter((key) => key.startsWith('$'));
if (specialKeys.length > 0) {
if (specialKeys.includes('$oid')) {
if (!hasExactKeys(['$oid'])) {
throw new Error('Invalid ObjectId format: extra keys not allowed');
}
const oidStr = obj.$oid;
if (typeof oidStr === 'string' && /^[0-9a-fA-F]{24}$/.test(oidStr)) {
return this.parseObjectId(oidStr);
}
throw new Error('Invalid ObjectId format');
}
if (specialKeys.includes('$numberInt')) {
if (!hasExactKeys(['$numberInt'])) {
throw new Error('Invalid Int32 format: extra keys not allowed');
}
const intStr = obj.$numberInt;
if (typeof intStr === 'string') {
const value = parseInt(intStr, 10);
if (!isNaN(value) && value >= -2147483648 && value <= 2147483647) {
return new values_1.BsonInt32(value);
}
}
throw new Error('Invalid Int32 format');
}
if (specialKeys.includes('$numberLong')) {
if (!hasExactKeys(['$numberLong'])) {
throw new Error('Invalid Int64 format: extra keys not allowed');
}
const longStr = obj.$numberLong;
if (typeof longStr === 'string') {
const value = parseFloat(longStr);
if (!isNaN(value)) {
return new values_1.BsonInt64(value);
}
}
throw new Error('Invalid Int64 format');
}
if (specialKeys.includes('$numberDouble')) {
if (!hasExactKeys(['$numberDouble'])) {
throw new Error('Invalid Double format: extra keys not allowed');
}
const doubleStr = obj.$numberDouble;
if (typeof doubleStr === 'string') {
if (doubleStr === 'Infinity')
return new values_1.BsonFloat(Infinity);
if (doubleStr === '-Infinity')
return new values_1.BsonFloat(-Infinity);
if (doubleStr === 'NaN')
return new values_1.BsonFloat(NaN);
const value = parseFloat(doubleStr);
if (!isNaN(value)) {
return new values_1.BsonFloat(value);
}
}
throw new Error('Invalid Double format');
}
if (specialKeys.includes('$numberDecimal')) {
if (!hasExactKeys(['$numberDecimal'])) {
throw new Error('Invalid Decimal128 format: extra keys not allowed');
}
const decimalStr = obj.$numberDecimal;
if (typeof decimalStr === 'string') {
return new values_1.BsonDecimal128(new Uint8Array(16));
}
throw new Error('Invalid Decimal128 format');
}
if (specialKeys.includes('$binary')) {
if (!hasExactKeys(['$binary'])) {
throw new Error('Invalid Binary format: extra keys not allowed');
}
const binaryObj = obj.$binary;
if (typeof binaryObj === 'object' && binaryObj !== null) {
const binaryKeys = Object.keys(binaryObj);
if (binaryKeys.length === 2 && binaryKeys.includes('base64') && binaryKeys.includes('subType')) {
const base64 = binaryObj.base64;
const subType = binaryObj.subType;
if (typeof base64 === 'string' && typeof subType === 'string') {
const data = this.base64ToUint8Array(base64);
const subtype = parseInt(subType, 16);
return new values_1.BsonBinary(subtype, data);
}
}
}
throw new Error('Invalid Binary format');
}
if (specialKeys.includes('$uuid')) {
if (!hasExactKeys(['$uuid'])) {
throw new Error('Invalid UUID format: extra keys not allowed');
}
const uuidStr = obj.$uuid;
if (typeof uuidStr === 'string' && this.isValidUuid(uuidStr)) {
const data = this.uuidToBytes(uuidStr);
return new values_1.BsonBinary(4, data);
}
throw new Error('Invalid UUID format');
}
if (specialKeys.includes('$code') && !specialKeys.includes('$scope')) {
if (!hasExactKeys(['$code'])) {
throw new Error('Invalid Code format: extra keys not allowed');
}
const code = obj.$code;
if (typeof code === 'string') {
return new values_1.BsonJavascriptCode(code);
}
throw new Error('Invalid Code format');
}
if (specialKeys.includes('$code') && specialKeys.includes('$scope')) {
if (!hasExactKeys(['$code', '$scope'])) {
throw new Error('Invalid CodeWScope format: extra keys not allowed');
}
const code = obj.$code;
const scope = obj.$scope;
if (typeof code === 'string' && typeof scope === 'object' && scope !== null) {
return new values_1.BsonJavascriptCodeWithScope(code, this.transformEjsonObject(scope));
}
throw new Error('Invalid CodeWScope format');
}
if (specialKeys.includes('$symbol')) {
if (!hasExactKeys(['$symbol'])) {
throw new Error('Invalid Symbol format: extra keys not allowed');
}
const symbol = obj.$symbol;
if (typeof symbol === 'string') {
return new values_1.BsonSymbol(symbol);
}
throw new Error('Invalid Symbol format');
}
if (specialKeys.includes('$timestamp')) {
if (!hasExactKeys(['$timestamp'])) {
throw new Error('Invalid Timestamp format: extra keys not allowed');
}
const timestampObj = obj.$timestamp;
if (typeof timestampObj === 'object' && timestampObj !== null) {
const timestampKeys = Object.keys(timestampObj);
if (timestampKeys.length === 2 && timestampKeys.includes('t') && timestampKeys.includes('i')) {
const t = timestampObj.t;
const i = timestampObj.i;
if (typeof t === 'number' && typeof i === 'number' && t >= 0 && i >= 0) {
return new values_1.BsonTimestamp(i, t);
}
}
}
throw new Error('Invalid Timestamp format');
}
if (specialKeys.includes('$regularExpression')) {
if (!hasExactKeys(['$regularExpression'])) {
throw new Error('Invalid RegularExpression format: extra keys not allowed');
}
const regexObj = obj.$regularExpression;
if (typeof regexObj === 'object' && regexObj !== null) {
const regexKeys = Object.keys(regexObj);
if (regexKeys.length === 2 && regexKeys.includes('pattern') && regexKeys.includes('options')) {
const pattern = regexObj.pattern;
const options = regexObj.options;
if (typeof pattern === 'string' && typeof options === 'string') {
return new RegExp(pattern, options);
}
}
}
throw new Error('Invalid RegularExpression format');
}
if (specialKeys.includes('$dbPointer')) {
if (!hasExactKeys(['$dbPointer'])) {
throw new Error('Invalid DBPointer format: extra keys not allowed');
}
const dbPointerObj = obj.$dbPointer;
if (typeof dbPointerObj === 'object' && dbPointerObj !== null) {
const dbPointerKeys = Object.keys(dbPointerObj);
if (dbPointerKeys.length === 2 && dbPointerKeys.includes('$ref') && dbPointerKeys.includes('$id')) {
const ref = dbPointerObj.$ref;
const id = dbPointerObj.$id;
if (typeof ref === 'string' && id !== undefined) {
const transformedId = this.transformEjsonObject(id);
if (transformedId instanceof values_1.BsonObjectId) {
return new values_1.BsonDbPointer(ref, transformedId);
}
}
}
}
throw new Error('Invalid DBPointer format');
}
if (specialKeys.includes('$date')) {
if (!hasExactKeys(['$date'])) {
throw new Error('Invalid Date format: extra keys not allowed');
}
const dateValue = obj.$date;
if (typeof dateValue === 'string') {
const date = new Date(dateValue);
if (!isNaN(date.getTime())) {
return date;
}
}
else if (typeof dateValue === 'object' && dateValue !== null) {
const longObj = dateValue;
const longKeys = Object.keys(longObj);
if (longKeys.length === 1 && longKeys[0] === '$numberLong' && typeof longObj.$numberLong === 'string') {
const timestamp = parseFloat(longObj.$numberLong);
if (!isNaN(timestamp)) {
return new Date(timestamp);
}
}
}
throw new Error('Invalid Date format');
}
if (specialKeys.includes('$minKey')) {
if (!hasExactKeys(['$minKey'])) {
throw new Error('Invalid MinKey format: extra keys not allowed');
}
if (obj.$minKey === 1) {
return new values_1.BsonMinKey();
}
throw new Error('Invalid MinKey format');
}
if (specialKeys.includes('$maxKey')) {
if (!hasExactKeys(['$maxKey'])) {
throw new Error('Invalid MaxKey format: extra keys not allowed');
}
if (obj.$maxKey === 1) {
return new values_1.BsonMaxKey();
}
throw new Error('Invalid MaxKey format');
}
if (specialKeys.includes('$undefined')) {
if (!hasExactKeys(['$undefined'])) {
throw new Error('Invalid Undefined format: extra keys not allowed');
}
if (obj.$undefined === true) {
return undefined;
}
throw new Error('Invalid Undefined format');
}
}
if (keys.includes('$ref') && keys.includes('$id')) {
const ref = obj.$ref;
const id = this.transformEjsonObject(obj.$id);
const result = { $ref: ref, $id: id };
if (keys.includes('$db')) {
result.$db = obj.$db;
}
for (const key of keys) {
if (key !== '$ref' && key !== '$id' && key !== '$db') {
result[key] = this.transformEjsonObject(obj[key]);
}
}
return result;
}
const result = {};
for (const [key, val] of Object.entries(obj)) {
if (typeof val === 'object' && val !== null && !Array.isArray(val)) {
result[key] = this.transformEjsonObject(val);
}
else if (Array.isArray(val)) {
result[key] = val.map((item) => typeof item === 'object' && item !== null && !Array.isArray(item)
? this.transformEjsonObject(item)
: item);
}
else {
result[key] = val;
}
}
return result;
}
parseObjectId(hex) {
const timestamp = parseInt(hex.slice(0, 8), 16);
const process = parseInt(hex.slice(8, 18), 16);
const counter = parseInt(hex.slice(18, 24), 16);
return new values_1.BsonObjectId(timestamp, process, counter);
}
base64ToUint8Array(base64) {
const binary = atob(base64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes;
}
isValidUuid(uuid) {
const uuidPattern = /^[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}$/;
return uuidPattern.test(uuid);
}
uuidToBytes(uuid) {
const hex = uuid.replace(/-/g, '');
const bytes = new Uint8Array(16);
for (let i = 0; i < 16; i++) {
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
}
return bytes;
}
}
exports.EjsonDecoder = EjsonDecoder;
//# sourceMappingURL=EjsonDecoder.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,41 @@
import { JsonEncoder } from '../json/JsonEncoder';
import type { IWriter, IWriterGrowable } from '@jsonjoy.com/buffers/lib';
export interface EjsonEncoderOptions {
canonical?: boolean;
}
export declare class EjsonEncoder extends JsonEncoder {
private options;
constructor(writer: IWriter & IWriterGrowable, options?: EjsonEncoderOptions);
encodeToString(value: unknown): string;
writeUnknown(value: unknown): void;
writeAny(value: unknown): void;
writeBin(buf: Uint8Array): void;
writeStr(str: string): void;
writeAsciiStr(str: string): void;
writeArr(arr: unknown[]): void;
writeObj(obj: Record<string, unknown>): void;
private writeUndefinedWrapper;
private writeNumberAsEjson;
private writeNumberIntWrapper;
private writeNumberLongWrapper;
private writeNumberDoubleWrapper;
private writeDateAsEjson;
private writeRegExpAsEjson;
private writeObjectIdAsEjson;
private writeBsonInt32AsEjson;
private writeBsonInt64AsEjson;
private writeBsonFloatAsEjson;
private writeBsonDecimal128AsEjson;
private writeBsonBinaryAsEjson;
private writeBsonCodeAsEjson;
private writeBsonCodeWScopeAsEjson;
private writeBsonSymbolAsEjson;
private writeBsonTimestampAsEjson;
private writeBsonDbPointerAsEjson;
private writeBsonMinKeyAsEjson;
private writeBsonMaxKeyAsEjson;
private formatNonFinite;
private objectIdToHex;
private uint8ArrayToBase64;
private decimal128ToString;
}

View File

@@ -0,0 +1,498 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EjsonEncoder = void 0;
const values_1 = require("../bson/values");
const toBase64Bin_1 = require("@jsonjoy.com/base64/lib/toBase64Bin");
const JsonEncoder_1 = require("../json/JsonEncoder");
class EjsonEncoder extends JsonEncoder_1.JsonEncoder {
constructor(writer, options = {}) {
super(writer);
this.options = options;
}
encodeToString(value) {
const bytes = this.encode(value);
return new TextDecoder().decode(bytes);
}
writeUnknown(value) {
this.writeNull();
}
writeAny(value) {
if (value === null || value === undefined) {
if (value === undefined) {
return this.writeUndefinedWrapper();
}
return this.writeNull();
}
if (typeof value === 'boolean') {
return this.writeBoolean(value);
}
if (typeof value === 'string') {
return this.writeStr(value);
}
if (typeof value === 'number') {
return this.writeNumberAsEjson(value);
}
if (Array.isArray(value)) {
return this.writeArr(value);
}
if (value instanceof Date) {
return this.writeDateAsEjson(value);
}
if (value instanceof RegExp) {
return this.writeRegExpAsEjson(value);
}
if (value instanceof values_1.BsonObjectId) {
return this.writeObjectIdAsEjson(value);
}
if (value instanceof values_1.BsonInt32) {
return this.writeBsonInt32AsEjson(value);
}
if (value instanceof values_1.BsonInt64) {
return this.writeBsonInt64AsEjson(value);
}
if (value instanceof values_1.BsonFloat) {
return this.writeBsonFloatAsEjson(value);
}
if (value instanceof values_1.BsonDecimal128) {
return this.writeBsonDecimal128AsEjson(value);
}
if (value instanceof values_1.BsonBinary) {
return this.writeBsonBinaryAsEjson(value);
}
if (value instanceof values_1.BsonJavascriptCode) {
return this.writeBsonCodeAsEjson(value);
}
if (value instanceof values_1.BsonJavascriptCodeWithScope) {
return this.writeBsonCodeWScopeAsEjson(value);
}
if (value instanceof values_1.BsonSymbol) {
return this.writeBsonSymbolAsEjson(value);
}
if (value instanceof values_1.BsonTimestamp) {
return this.writeBsonTimestampAsEjson(value);
}
if (value instanceof values_1.BsonDbPointer) {
return this.writeBsonDbPointerAsEjson(value);
}
if (value instanceof values_1.BsonMinKey) {
return this.writeBsonMinKeyAsEjson();
}
if (value instanceof values_1.BsonMaxKey) {
return this.writeBsonMaxKeyAsEjson();
}
if (typeof value === 'object' && value !== null) {
return this.writeObj(value);
}
return this.writeUnknown(value);
}
writeBin(buf) {
const writer = this.writer;
const length = buf.length;
writer.ensureCapacity(38 + 3 + (length << 1));
const view = writer.view;
let x = writer.x;
view.setUint32(x, 577003892);
x += 4;
view.setUint32(x, 1631215984);
x += 4;
view.setUint32(x, 1886153059);
x += 4;
view.setUint32(x, 1635019119);
x += 4;
view.setUint32(x, 1848602467);
x += 4;
view.setUint32(x, 1952805933);
x += 4;
view.setUint32(x, 1937011301);
x += 4;
view.setUint32(x, 1634548578);
x += 4;
view.setUint32(x, 1634952502);
x += 4;
view.setUint16(x, 13356);
x += 2;
x = (0, toBase64Bin_1.toBase64Bin)(buf, 0, length, view, x);
writer.uint8[x++] = 0x22;
writer.x = x;
}
writeStr(str) {
const writer = this.writer;
const length = str.length;
writer.ensureCapacity(length * 4 + 2);
if (length < 256) {
let x = writer.x;
const uint8 = writer.uint8;
uint8[x++] = 0x22;
for (let i = 0; i < length; i++) {
const code = str.charCodeAt(i);
switch (code) {
case 34:
case 92:
uint8[x++] = 0x5c;
break;
}
if (code < 32 || code > 126) {
writer.utf8(JSON.stringify(str));
return;
}
else
uint8[x++] = code;
}
uint8[x++] = 0x22;
writer.x = x;
return;
}
writer.utf8(JSON.stringify(str));
}
writeAsciiStr(str) {
const length = str.length;
const writer = this.writer;
writer.ensureCapacity(length * 2 + 2);
const uint8 = writer.uint8;
let x = writer.x;
uint8[x++] = 0x22;
for (let i = 0; i < length; i++) {
const code = str.charCodeAt(i);
switch (code) {
case 34:
case 92:
uint8[x++] = 0x5c;
break;
}
uint8[x++] = code;
}
uint8[x++] = 0x22;
writer.x = x;
}
writeArr(arr) {
const writer = this.writer;
writer.u8(0x5b);
const length = arr.length;
const last = length - 1;
for (let i = 0; i < last; i++) {
this.writeAny(arr[i]);
writer.u8(0x2c);
}
if (last >= 0)
this.writeAny(arr[last]);
writer.u8(0x5d);
}
writeObj(obj) {
const writer = this.writer;
const keys = Object.keys(obj);
const length = keys.length;
if (!length)
return writer.u16(0x7b7d);
writer.u8(0x7b);
for (let i = 0; i < length; i++) {
const key = keys[i];
const value = obj[key];
this.writeStr(key);
writer.u8(0x3a);
this.writeAny(value);
writer.u8(0x2c);
}
writer.uint8[writer.x - 1] = 0x7d;
}
writeUndefinedWrapper() {
const writer = this.writer;
writer.ensureCapacity(18);
writer.u8(0x7b);
writer.u32(0x2224756e);
writer.u32(0x64656669);
writer.u32(0x6e656422);
writer.u8(0x3a);
writer.u32(0x74727565);
writer.u8(0x7d);
}
writeNumberAsEjson(value) {
if (this.options.canonical) {
if (Number.isInteger(value)) {
if (value >= -2147483648 && value <= 2147483647) {
this.writeNumberIntWrapper(value);
}
else {
this.writeNumberLongWrapper(value);
}
}
else {
this.writeNumberDoubleWrapper(value);
}
}
else {
if (!isFinite(value)) {
this.writeNumberDoubleWrapper(value);
}
else {
this.writeNumber(value);
}
}
}
writeNumberIntWrapper(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x496e7422);
writer.u8(0x3a);
this.writeStr(value + '');
writer.u8(0x7d);
}
writeNumberLongWrapper(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x4c6f6e67);
writer.u16(0x223a);
this.writeStr(value + '');
writer.u8(0x7d);
}
writeNumberDoubleWrapper(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x446f7562);
writer.u16(0x6c65);
writer.u16(0x223a);
if (!isFinite(value)) {
this.writeStr(this.formatNonFinite(value));
}
else {
this.writeStr(value + '');
}
writer.u8(0x7d);
}
writeDateAsEjson(value) {
const timestamp = value.getTime();
if (isNaN(timestamp)) {
throw new Error('Invalid Date');
}
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246461);
writer.u16(0x7465);
writer.u16(0x223a);
if (this.options.canonical) {
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x4c6f6e67);
writer.u16(0x223a);
this.writeStr(timestamp + '');
writer.u8(0x7d);
}
else {
const year = value.getFullYear();
if (year >= 1970 && year <= 9999) {
this.writeStr(value.toISOString());
}
else {
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x4c6f6e67);
writer.u16(0x223a);
this.writeStr(timestamp + '');
writer.u8(0x7d);
}
}
writer.u8(0x7d);
}
writeRegExpAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22247265);
writer.u32(0x67756c61);
writer.u32(0x72457870);
writer.u32(0x72657373);
writer.u32(0x696f6e22);
writer.u16(0x3a7b);
writer.u32(0x22706174);
writer.u32(0x7465726e);
writer.u16(0x223a);
this.writeStr(value.source);
writer.u8(0x2c);
writer.u32(0x226f7074);
writer.u32(0x696f6e73);
writer.u16(0x223a);
this.writeStr(value.flags);
writer.u16(0x7d7d);
}
writeObjectIdAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246f69);
writer.u16(0x6422);
writer.u8(0x3a);
this.writeStr(this.objectIdToHex(value));
writer.u8(0x7d);
}
writeBsonInt32AsEjson(value) {
if (this.options.canonical) {
this.writeNumberIntWrapper(value.value);
}
else {
this.writeNumber(value.value);
}
}
writeBsonInt64AsEjson(value) {
if (this.options.canonical) {
this.writeNumberLongWrapper(value.value);
}
else {
this.writeNumber(value.value);
}
}
writeBsonFloatAsEjson(value) {
if (this.options.canonical) {
this.writeNumberDoubleWrapper(value.value);
}
else {
if (!isFinite(value.value)) {
this.writeNumberDoubleWrapper(value.value);
}
else {
this.writeNumber(value.value);
}
}
}
writeBsonDecimal128AsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246e75);
writer.u32(0x6d626572);
writer.u32(0x44656369);
writer.u32(0x6d616c22);
writer.u8(0x3a);
this.writeStr(this.decimal128ToString(value.data));
writer.u8(0x7d);
}
writeBsonBinaryAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246269);
writer.u32(0x6e617279);
writer.u16(0x223a);
writer.u8(0x7b);
writer.u32(0x22626173);
writer.u32(0x65363422);
writer.u8(0x3a);
this.writeStr(this.uint8ArrayToBase64(value.data));
writer.u8(0x2c);
writer.u32(0x22737562);
writer.u32(0x54797065);
writer.u16(0x223a);
this.writeStr(value.subtype.toString(16).padStart(2, '0'));
writer.u16(0x7d7d);
}
writeBsonCodeAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x2224636f);
writer.u16(0x6465);
writer.u16(0x223a);
this.writeStr(value.code);
writer.u8(0x7d);
}
writeBsonCodeWScopeAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x2224636f);
writer.u16(0x6465);
writer.u16(0x223a);
this.writeStr(value.code);
writer.u8(0x2c);
writer.u32(0x22247363);
writer.u32(0x6f706522);
writer.u8(0x3a);
this.writeAny(value.scope);
writer.u8(0x7d);
}
writeBsonSymbolAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22247379);
writer.u32(0x6d626f6c);
writer.u16(0x223a);
this.writeStr(value.symbol);
writer.u8(0x7d);
}
writeBsonTimestampAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22247469);
writer.u32(0x6d657374);
writer.u32(0x616d7022);
writer.u16(0x3a7b);
writer.u16(0x2274);
writer.u16(0x223a);
this.writeNumber(value.timestamp);
writer.u8(0x2c);
writer.u16(0x2269);
writer.u16(0x223a);
this.writeNumber(value.increment);
writer.u16(0x7d7d);
}
writeBsonDbPointerAsEjson(value) {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246462);
writer.u32(0x506f696e);
writer.u32(0x74657222);
writer.u16(0x3a7b);
writer.u32(0x22247265);
writer.u16(0x6622);
writer.u8(0x3a);
this.writeStr(value.name);
writer.u8(0x2c);
writer.u32(0x22246964);
writer.u16(0x223a);
this.writeAny(value.id);
writer.u16(0x7d7d);
}
writeBsonMinKeyAsEjson() {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246d69);
writer.u32(0x6e4b6579);
writer.u16(0x223a);
this.writeNumber(1);
writer.u8(0x7d);
}
writeBsonMaxKeyAsEjson() {
const writer = this.writer;
writer.u8(0x7b);
writer.u32(0x22246d61);
writer.u32(0x784b6579);
writer.u16(0x223a);
this.writeNumber(1);
writer.u8(0x7d);
}
formatNonFinite(value) {
if (value === Infinity)
return 'Infinity';
if (value === -Infinity)
return '-Infinity';
return 'NaN';
}
objectIdToHex(objectId) {
const timestamp = objectId.timestamp.toString(16).padStart(8, '0');
const process = objectId.process.toString(16).padStart(10, '0');
const counter = objectId.counter.toString(16).padStart(6, '0');
return timestamp + process + counter;
}
uint8ArrayToBase64(data) {
let binary = '';
for (let i = 0; i < data.length; i++) {
binary += String.fromCharCode(data[i]);
}
return btoa(binary);
}
decimal128ToString(data) {
return '0';
}
}
exports.EjsonEncoder = EjsonEncoder;
//# sourceMappingURL=EjsonEncoder.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
export { EjsonEncoder, type EjsonEncoderOptions } from './EjsonEncoder';
export { EjsonDecoder, type EjsonDecoderOptions } from './EjsonDecoder';
export { BsonBinary, BsonDbPointer, BsonDecimal128, BsonFloat, BsonInt32, BsonInt64, BsonJavascriptCode, BsonJavascriptCodeWithScope, BsonMaxKey, BsonMinKey, BsonObjectId, BsonSymbol, BsonTimestamp, } from '../bson/values';

22
node_modules/@jsonjoy.com/json-pack/lib/ejson/index.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BsonTimestamp = exports.BsonSymbol = exports.BsonObjectId = exports.BsonMinKey = exports.BsonMaxKey = exports.BsonJavascriptCodeWithScope = exports.BsonJavascriptCode = exports.BsonInt64 = exports.BsonInt32 = exports.BsonFloat = exports.BsonDecimal128 = exports.BsonDbPointer = exports.BsonBinary = exports.EjsonDecoder = exports.EjsonEncoder = void 0;
var EjsonEncoder_1 = require("./EjsonEncoder");
Object.defineProperty(exports, "EjsonEncoder", { enumerable: true, get: function () { return EjsonEncoder_1.EjsonEncoder; } });
var EjsonDecoder_1 = require("./EjsonDecoder");
Object.defineProperty(exports, "EjsonDecoder", { enumerable: true, get: function () { return EjsonDecoder_1.EjsonDecoder; } });
var values_1 = require("../bson/values");
Object.defineProperty(exports, "BsonBinary", { enumerable: true, get: function () { return values_1.BsonBinary; } });
Object.defineProperty(exports, "BsonDbPointer", { enumerable: true, get: function () { return values_1.BsonDbPointer; } });
Object.defineProperty(exports, "BsonDecimal128", { enumerable: true, get: function () { return values_1.BsonDecimal128; } });
Object.defineProperty(exports, "BsonFloat", { enumerable: true, get: function () { return values_1.BsonFloat; } });
Object.defineProperty(exports, "BsonInt32", { enumerable: true, get: function () { return values_1.BsonInt32; } });
Object.defineProperty(exports, "BsonInt64", { enumerable: true, get: function () { return values_1.BsonInt64; } });
Object.defineProperty(exports, "BsonJavascriptCode", { enumerable: true, get: function () { return values_1.BsonJavascriptCode; } });
Object.defineProperty(exports, "BsonJavascriptCodeWithScope", { enumerable: true, get: function () { return values_1.BsonJavascriptCodeWithScope; } });
Object.defineProperty(exports, "BsonMaxKey", { enumerable: true, get: function () { return values_1.BsonMaxKey; } });
Object.defineProperty(exports, "BsonMinKey", { enumerable: true, get: function () { return values_1.BsonMinKey; } });
Object.defineProperty(exports, "BsonObjectId", { enumerable: true, get: function () { return values_1.BsonObjectId; } });
Object.defineProperty(exports, "BsonSymbol", { enumerable: true, get: function () { return values_1.BsonSymbol; } });
Object.defineProperty(exports, "BsonTimestamp", { enumerable: true, get: function () { return values_1.BsonTimestamp; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ejson/index.ts"],"names":[],"mappings":";;;AAIA,+CAAsE;AAA9D,4GAAA,YAAY,OAAA;AACpB,+CAAsE;AAA9D,4GAAA,YAAY,OAAA;AAGpB,yCAcwB;AAbtB,oGAAA,UAAU,OAAA;AACV,uGAAA,aAAa,OAAA;AACb,wGAAA,cAAc,OAAA;AACd,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,4GAAA,kBAAkB,OAAA;AAClB,qHAAA,2BAA2B,OAAA;AAC3B,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,sGAAA,YAAY,OAAA;AACZ,oGAAA,UAAU,OAAA;AACV,uGAAA,aAAa,OAAA"}