[
  {
    "path": ".eslintrc.js",
    "content": "/* eslint max-lines: \"off\" */\n\nmodule.exports = {\n\tenv: {\n\t\tbrowser: true,\n\t\tcommonjs: true,\n\t\tes6: true,\n\t\tnode: true,\n\t},\n\textends: 'eslint:recommended',\n\tparserOptions: { sourceType: 'module' },\n\trules: {\n\t\t'accessor-pairs': ['error'],\n\t\t'array-bracket-spacing': ['warn', 'never'],\n\t\t'array-callback-return': ['warn'],\n\t\t'arrow-body-style': ['error'],\n\t\t'arrow-parens': ['error', 'always'],\n\t\t'arrow-spacing': ['error', {\n\t\t\tafter: true,\n\t\t\tbefore: true,\n\t\t}],\n\t\t'block-scoped-var': ['off'],\n\t\t'block-spacing': ['warn', 'always'],\n\t\t'brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],\n\t\t'callback-return': ['warn'],\n\t\t'camelcase': ['off'], //<- consider error, never\n\t\t'capitalized-comments': ['off'],\n\t\t'class-methods-use-this': ['off'],\n\t\t'comma-dangle': ['error', 'always-multiline'],\n\t\t'comma-spacing': ['error'],\n\t\t'comma-style': ['error'],\n\t\t'complexity': ['warn', { max: 15 }],\n\t\t'computed-property-spacing': ['error'],\n\t\t'consistent-return': ['off'],\n\t\t'consistent-this': ['error'],\n\t\t'constructor-super': ['error'],\n\t\t'curly': ['error', 'all'],\n\t\t'default-case': ['off'],\n\t\t'dot-location': ['error', 'property'],\n\t\t'dot-notation': ['error'],\n\t\t'eol-last': ['warn', 'always'],\n\t\t'eqeqeq': ['error'],\n\t\t'func-call-spacing': ['error', 'never'],\n\t\t'func-name-matching': ['off'],\n\t\t'func-names': ['off'],\n\t\t'func-style': ['off'],\n\t\t'generator-star-spacing': ['error', 'after'],\n\t\t'global-require': ['error'],\n\t\t'guard-for-in': ['warn'],\n\t\t'handle-callback-err': ['warn'],\n\t\t'id-blacklist': ['off'],\n\t\t'id-length': ['off'],\n\t\t'id-match': ['off'],\n\t\t'indent': ['error', 'tab'],\n\t\t'init-declarations': ['off'],\n\t\t'jsx-quotes': ['off'],\n\t\t'key-spacing': ['error'],\n\t\t'keyword-spacing': ['error', { after: true }],\n\t\t'line-comment-position': ['off'],\n\t\t'linebreak-style': ['error', 'unix'],\n\t\t'lines-around-comment': ['off'],\n\t\t'lines-around-directive': ['error'],\n\t\t'max-depth': ['warn', { max: 4 }],\n\t\t'max-len': ['error', {\n\t\t\tcode: 100,\n\t\t\tignoreRegExpLiterals: true,\n\t\t\tignoreStrings: true,\n\t\t\tignoreTemplateLiterals: true,\n\t\t\tignoreUrls: true,\n\t\t\ttabWidth: 2,\n\t\t}],\n\t\t'max-lines': ['error', {\n\t\t\tmax: 200,\n\t\t\tskipBlankLines: true,\n\t\t\tskipComments: true,\n\t\t}],\n\t\t'max-nested-callbacks': ['warn', { max: 5 }],\n\t\t'max-params': ['warn', { max: 3 }],\n\t\t'max-statements': ['warn', { max: 20 }],\n\t\t'max-statements-per-line': ['error', { max: 2 }],\n\t\t'multiline-ternary': ['off'],\n\t\t'new-cap': ['off'],\n\t\t'new-parens': ['off'],\n\t\t'newline-after-var': ['warn', 'always'],\n\t\t'newline-before-return': ['warn'],\n\t\t'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 3 }],\n\t\t'no-alert': ['error'],\n\t\t'no-array-constructor': ['error'],\n\t\t'no-await-in-loop': ['warn'],\n\t\t'no-bitwise': ['off'],\n\t\t'no-caller': ['error'],\n\t\t'no-case-declarations': ['error'],\n\t\t'no-catch-shadow': ['error'],\n\t\t'no-class-assign': ['error'],\n\t\t'no-cond-assign': ['error', 'except-parens'],\n\t\t'no-confusing-arrow': ['error', { allowParens: true }],\n\t\t'no-console': ['error'],\n\t\t'no-const-assign': ['error'],\n\t\t'no-constant-condition': ['error'],\n\t\t'no-continue': ['off'],\n\t\t'no-control-regex': ['off'],\n\t\t'no-debugger': ['error'],\n\t\t'no-delete-var': ['error'],\n\t\t'no-div-regex': ['error'],\n\t\t'no-dupe-args': ['error'],\n\t\t'no-dupe-class-members': ['error'],\n\t\t'no-dupe-keys': ['error'],\n\t\t'no-duplicate-case': ['error'],\n\t\t'no-duplicate-imports': ['error'],\n\t\t'no-else-return': ['off'],\n\t\t'no-empty': ['error'],\n\t\t'no-empty-character-class': ['error'],\n\t\t'no-empty-function': ['off'],\n\t\t'no-empty-pattern': ['error'],\n\t\t'no-eq-null': ['error'],\n\t\t'no-eval': ['error'],\n\t\t'no-ex-assign': ['error'],\n\t\t'no-extend-native': ['error'],\n\t\t'no-extra-bind': ['error'],\n\t\t'no-extra-boolean-cast': ['error'],\n\t\t'no-extra-label': ['warn'],\n\t\t'no-extra-parens': ['error', 'functions'],\n\t\t'no-extra-semi': ['error'],\n\t\t'no-fallthrough': ['error'],\n\t\t'no-floating-decimal': ['error'],\n\t\t'no-func-assign': ['error'],\n\t\t'no-global-assign': ['error'],\n\t\t'no-implicit-coercion': ['error'],\n\t\t'no-implicit-globals': ['warn'],\n\t\t'no-implied-eval': ['error'],\n\t\t'no-inline-comments': ['off'],\n\t\t'no-inner-declarations': ['error', 'functions'],\n\t\t'no-invalid-regexp': ['error'],\n\t\t'no-invalid-this': ['error'],\n\t\t'no-irregular-whitespace': ['error'],\n\t\t'no-iterator': ['error'],\n\t\t'no-label-var': ['error'],\n\t\t'no-labels': ['off'],\n\t\t'no-lone-blocks': ['error'],\n\t\t'no-lonely-if': ['error'],\n\t\t'no-loop-func': ['error'],\n\t\t'no-magic-numbers': ['error', {\n\t\t\tenforceConst: true,\n\t\t\tignore: [-1, 0, 1],\n\t\t\tignoreArrayIndexes: true,\n\t\t}],\n\t\t'no-mixed-operators': ['off'],\n\t\t'no-mixed-requires': ['off'],\n\t\t'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'],\n\t\t'no-multi-assign': ['off'],\n\t\t'no-multi-spaces': ['error'],\n\t\t'no-multi-str': ['off'],\n\t\t'no-multiple-empty-lines': ['error', {\n\t\t\tmax: 1,\n\t\t\tmaxBOF: 0,\n\t\t\tmaxEOF: 1,\n\t\t}],\n\t\t'no-negated-condition': ['off'],\n\t\t'no-nested-ternary': ['off'],\n\t\t'no-new': ['warn'],\n\t\t'no-new-func': ['error'],\n\t\t'no-new-object': ['error'],\n\t\t'no-new-require': ['warn'],\n\t\t'no-new-symbol': ['error'],\n\t\t'no-new-wrappers': ['error'],\n\t\t'no-obj-calls': ['error'],\n\t\t'no-octal-escape': ['error'],\n\t\t'no-param-reassign': ['error'],\n\t\t'no-path-concat': ['warn'],\n\t\t'no-plusplus': ['off'],\n\t\t'no-process-env': ['error'],\n\t\t'no-process-exit': ['error'],\n\t\t'no-proto': ['error'],\n\t\t'no-prototype-builtins': ['off'],\n\t\t'no-redeclare': ['error'],\n\t\t'no-regex-spaces': ['off'],\n\t\t'no-restricted-globals': ['off'],\n\t\t'no-restricted-imports': ['off'],\n\t\t'no-restricted-modules': ['off'],\n\t\t'no-restricted-properties': ['off'],\n\t\t'no-restricted-syntax': ['off'],\n\t\t'no-return-assign': ['error', 'except-parens'],\n\t\t'no-return-await': ['error'],\n\t\t'no-script-url': ['error'],\n\t\t'no-self-assign': ['error'],\n\t\t'no-self-compare': ['error'],\n\t\t'no-sequences': ['error'],\n\t\t'no-shadow': ['warn', { builtinGlobals: true }],\n\t\t'no-shadow-restricted-names': ['error'],\n\t\t'no-sparse-arrays': ['error'],\n\t\t'no-sync': ['warn'],\n\t\t'no-tabs': ['off'],\n\t\t'no-template-curly-in-string': ['error'],\n\t\t'no-ternary': ['off'],\n\t\t'no-this-before-super': ['error'],\n\t\t'no-throw-literal': ['error'],\n\t\t'no-trailing-spaces': ['error'],\n\t\t'no-undef': ['error'],\n\t\t'no-undef-init': ['off'],\n\t\t'no-undefined': ['off'],\n\t\t'no-underscore-dangle': ['off'],\n\t\t'no-unexpected-multiline': ['error'],\n\t\t'no-unmodified-loop-condition': ['warn'],\n\t\t'no-unneeded-ternary': ['error', { defaultAssignment: false }],\n\t\t'no-unreachable': ['error'],\n\t\t'no-unsafe-finally': ['error'],\n\t\t'no-unsafe-negation': ['error'],\n\t\t'no-unused-expressions': ['error', {\n\t\t\tallowShortCircuit: true,\n\t\t\tallowTernary: false,\n\t\t}],\n\t\t'no-unused-labels': ['error'],\n\t\t'no-unused-vars': ['error', {\n\t\t\targs: 'all',\n\t\t\targsIgnorePattern: '^_',\n\t\t\tcaughtErrorsIgnorePattern: '^_',\n\t\t\tignoreRestSiblings: true,\n\t\t\tvars: 'all',\n\t\t\tvarsIgnorePattern: '^_',\n\t\t}],\n\t\t'no-use-before-define': ['error', {\n\t\t\tclasses: false,\n\t\t\tfunctions: false,\n\t\t}],\n\t\t'no-useless-call': ['error'],\n\t\t'no-useless-computed-key': ['error'],\n\t\t'no-useless-concat': ['warn'],\n\t\t'no-useless-constructor': ['error'],\n\t\t'no-useless-escape': ['warn'],\n\t\t'no-useless-rename': ['warn'],\n\t\t'no-useless-return': ['warn'],\n\t\t'no-var': ['off'],\n\t\t'no-void': ['warn'],\n\t\t'no-warning-comments': ['warn'],\n\t\t'no-whitespace-before-property': ['error'],\n\t\t'no-with': ['error'],\n\t\t'object-curly-newline': ['error', {\n\t\t\tminProperties: 3,\n\t\t\tmultiline: true,\n\t\t}],\n\t\t'object-curly-spacing': ['error', 'always'],\n\t\t'object-property-newline': ['off'],\n\t\t'object-shorthand': ['off'],\n\t\t'one-var': ['off'],\n\t\t'one-var-declaration-per-line': ['error', 'initializations'],\n\t\t'operator-assignment': ['off'],\n\t\t'operator-linebreak': ['error', 'before'],\n\t\t'padded-blocks': ['error', 'never'],\n\t\t'prefer-arrow-callback': ['warn'],\n\t\t'prefer-const': ['warn'],\n\t\t'prefer-destructuring': ['off'],\n\t\t'prefer-numeric-literals': ['warn'],\n\t\t'prefer-promise-reject-errors': ['error'],\n\t\t'prefer-rest-params': ['warn'],\n\t\t'prefer-spread': ['warn'],\n\t\t'prefer-template': ['warn'],\n\t\t'quote-props': ['error', 'consistent-as-needed'],\n\t\t'quotes': ['error', 'single', { allowTemplateLiterals: true }],\n\t\t'radix': ['error', 'always'],\n\t\t'require-await': ['error'],\n\t\t'require-jsdoc': ['off'],\n\t\t'require-yield': ['error'],\n\t\t'rest-spread-spacing': ['error', 'never'],\n\t\t'semi': ['error', 'never'],\n\t\t'semi-spacing': ['error', {\n\t\t\tafter: true,\n\t\t\tbefore: false,\n\t\t}],\n\t\t'sort-imports': ['off'],\n\t\t'sort-keys': ['warn', 'asc', {\n\t\t\tcaseSensitive: true,\n\t\t\tnatural: true,\n\t\t}],\n\t\t'sort-vars': ['warn'],\n\t\t'space-before-blocks': ['error', 'always'],\n\t\t'space-before-function-paren': ['error', {\n\t\t\tanonymous: 'always',\n\t\t\tasyncArrow: 'always',\n\t\t\tnamed: 'never',\n\t\t}],\n\t\t'space-in-parens': ['error', 'never'],\n\t\t'space-infix-ops': ['error', { int32Hint: false }],\n\t\t'space-unary-ops': ['error', {\n\t\t\tnonwords: false,\n\t\t\twords: true,\n\t\t}],\n\t\t'spaced-comment': ['off'],\n\t\t'strict': ['error'],\n\t\t'symbol-description': ['error'],\n\t\t'template-curly-spacing': ['off'],\n\t\t'template-tag-spacing': ['error', 'always'],\n\t\t'unicode-bom': ['error'],\n\t\t'use-isnan': ['error'],\n\t\t'valid-jsdoc': ['warn'],\n\t\t'valid-typeof': ['error'],\n\t\t'vars-on-top': ['off'],\n\t\t'wrap-iife': ['error', 'inside', { functionPrototypeMethods: true }],\n\t\t'wrap-regex': ['off'],\n\t\t'yield-star-spacing': ['error', 'after'],\n\t\t'yoda': ['off'],\n\t},\n}\n"
  },
  {
    "path": ".gitignore",
    "content": ".node-version\nnode_modules/\nyarn.lock\n*.swp\n"
  },
  {
    "path": "CHANGES",
    "content": "- 0.1.0 : Move extraneous exports from index.js into utils.js.\n- 0.2.0 : Add browser support for Browserify/Webpack.\n- 0.3.0 : Pass named arguments to .generate instead of positional.\n- 1.0.0 : Added support for Uuid V1 and extracted competitive benchmarks.\n- 1.0.1 : Remove lockfile from release.\n- 1.0.2 : Fix bad version push.\n- 1.0.3 : Delete the extra benchmarks for real.\n- 1.1.0 : Performance improvements and renamed resetClockSequence to reset.\n- 1.1.1 : Fixed repo link.\n- 1.2.0 : Added generic UUID factory.\n- 1.3.0 : Added UUID V6 support.\n- 1.4.0 : Exposed encoding verifiers.\n- 1.5.0 : Fixed benchmarks and added support for node +12.5.\n- 1.6.0 : Added Typescript support and top-level id comparators.\n- 1.6.1 : Tweaked random memory allocation and updated benchmarks.\n- 1.6.2 : Fixed docs\n- 1.6.3 : Fixed memory profile by reusing the buffer of random.\n- 1.6.4 : Fixed worker support\n- 1.6.5 : Removed erroneous packaged files\n- 1.6.6 : Fix CHANGES and add credit for worker support\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright 2018 Aaron Cohen <aarondcohen@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Id128\n\nGenerate 128-bit unique identifiers for various specifications.  In particular:\n- [ULID](#ulid)\n- [Monotonic ULID](#ulidmonotonic)\n- [UUID 1 (Variant 1 Version 1)](#uuid1)\n- [UUID 4 (Variant 1 Version 4)](#uuid4)\n- [UUID 6 (Variant 1 Version 6)](#uuid6)\n- [Nil UUID (Variant 0 Version 0)](#uuidnil)\n- [Uuid (Unknown Variant and Version)](#uuid)\n\n# Common Usage\n\n```es6\nconst {\n\tUlid,\n\tUlidMonotonic,\n\tUuid,\n\tUuid1,\n\tUuid4,\n\tUuid6,\n\tUuidNil,\n\tidCompare,\n\tidEqual,\n} = require('id128');\n\n// Id factories\n[\n\tUlid,\n\tUlidMonotonic,\n\tUuid1,\n\tUuid4,\n\tUuid6,\n\tUuidNil,\n].forEach((IdType) => {\n\t// Identify the factory\n\tconsole.log(IdType.name);\n\n\t// Generate a new id\n\tconst id = IdType.generate();\n\n\t// Get the smallest valid id\n\tconst min = IdType.MIN();\n\n\t// Get the largest valid id\n\tconst max = IdType.MAX();\n\n\t// Type-check the id\n\tconsole.log(id instanceof IdType.type)\n\n\t// Compare ids\n\tconsole.log(id.equal(id));\n\tconsole.log(! id.equal(min));\n\tconsole.log(! id.equal(max));\n\tconsole.log(id.compare(min) === 1);\n\tconsole.log(id.compare(id) === 0);\n\tconsole.log(id.compare(max) === -1);\n\n\t// Encode the id in its canonical form\n\tconst canonical = id.toCanonical();\n\tconsole.log(canonical);\n\n\t// Encode the id for efficient db storage\n\tconst raw = id.toRaw();\n\tconsole.log(raw);\n\n\t// Verify a canonically formatted id\n\tconsole.log(IdType.isCanonical(canonical));\n\n\t// Decode a valid canonically formatted id\n\tconsole.log(id.equal(IdType.fromCanonical(canonical)));\n\n\t// Decode a canonically formatted id, skipping validation\n\tconsole.log(id.equal(IdType.fromCanonicalTrusted(canonical)));\n\n\t// Verify a raw formatted id\n\tconsole.log(IdType.isRaw(raw));\n\n\t// Decode a valid raw formatted id\n\tconsole.log(id.equal(IdType.fromRaw(raw)));\n\n\t// Decode a raw formatted id, skipping validation\n\tconsole.log(id.equal(IdType.fromRawTrusted(raw)));\n});\n\n// Uuid Factory\n[0, 1, 4, 6].forEach((version) => {\n\t// Generate a new id\n\tconst id = Uuid.generate({ version });\n\n\t// Get the smallest valid id\n\tconst min = Uuid.MIN({ version });\n\n\t// Get the largest valid id\n\tconst max = Uuid.MAX({ version });\n\n\t// Type-check the id\n\tconsole.log(id instanceof Uuid.type)\n\n\t// Encode the id in its canonical form\n\tconst canonical = id.toCanonical();\n\tconsole.log(canonical);\n\n\t// Encode the id for efficient db storage\n\tconst raw = id.toRaw();\n\tconsole.log(raw);\n\n\t// Decode a valid canonically formatted id\n\tconsole.log(id.equal(Uuid.fromCanonical(canonical)));\n\n\t// Decode a canonically formatted id, skipping validation\n\tconsole.log(id.equal(Uuid.fromCanonicalTrusted(canonical)));\n\n\t// Decode a valid raw formatted id\n\tconsole.log(id.equal(Uuid.fromRaw(raw)));\n\n\t// Decode a raw formatted id, skipping validation\n\tconsole.log(id.equal(Uuid.fromRawTrusted(raw)));\n});\n\n// Static Utilities\n\n// Equate arbitrary ids\nconsole.log(idEqual(Ulid.generate(), Uuid4.generate()))\n\n// Compare arbitrary ids\nconsole.log(idCompare(Ulid.generate(), Uuid4.generate()))\n```\n\n## Common Factory Properties\n\n### name\nReturn the name of the generated id type.\n\n### type\nReturn the type of the generated id instances for type-checking\nwith the `instanceof` operator.\n\n## Common Factory Methods\n\n### .construct(bytes) => id\nReturn a new id instance without validating the bytes.\n\n### .generate() => id\nReturn a new id instance.\n\n### .MIN() => id\nReturn the id instance with the smallest valid value.\n\n### .MAX() => id\nReturn the id instance with the largest valid value.\n\n### .fromCanonical(canonical_string) => id\nDecode an id from its canonical representation.\nThrow `InvalidEncoding` if the string is undecodable.\n\n### .fromCanonicalTrusted(canonical_string) => id\nDecode an id from its canonical representation.\nSkip validation and assume the input is decodable.\n\n### .fromRaw(raw_string) => id\nDecode an id from its raw representation.\nThrow `InvalidEncoding` if the string is undecodable.\n\n### .fromRawTrusted(raw_string) => id\nDecode an id from its raw representation.\nSkip validation and assume the input is decodable.\n\n### .toCanonical(id) => canonical_string\nEncode the given id in the canonical form.\nThrow `InvalidBytes` if the id is not 128-bit conformant.\n\n### .toRaw(id) => raw_string\nEncode the given id in the raw form.\nThrow `InvalidBytes` if the id is not 128-bit conformant.\n\n### .isCanonical(canonical_string) => (true|false)\nVerify if a string is a valid canonical encoding.\n\n### .isRaw(raw_string) => (true|false)\nVerify if a string is a valid raw encoding.\n\n## Common Instance Properties\n\n### bytes\nReturn the actual byte array representing the id.\n\n## Common Instance Methods\n\n### .clone() => deep_copy\nReturn a new instance of the id with the same bit signature.\n\n### .compare(other) => (-1|0|1)\nDetermine how this id is ordered against another.\n\n### .equal(other) => (true|false)\nDetermine if this id has the same bytes as another.\n\n### .toCanonical() => canonical_string\nEncode this id in its canonical form.\n\n### .toRaw() => raw_string\nEncode this id in its raw form.\n\n## Namespace Static Utilities\n\n### idCompare(left_id, right_id) => (-1|0|1)\nDetermine if the left id is `less than | equal to | greater than`\nthe right id using lexicographical byte order.\n\n### idEqual(left_id, right_id) => (true|false)\nDetermine if 2 ids have the same byte value.\n\n# Ulid\n```es6\nconst { Ulid } = require('id128');\n```\n\nUlid, as [specified](https://github.com/ulid/spec), has some nice properties:\n- collision resistant: 80-bits of randomness\n- k-ordered: prefixed with millisecond precision timestamp\n- database friendly: fits within a uuid and generally appends to the index\n- human friendly: canonically encodes as a case-insensitive Crockford 32 number\n\nIt is useful when you need a distributed domain unique id.\n\n## Additional Instance Properties\n\n### time\nReturn a Date object for the epoch milliseconds encoded in the id.\n\n## Additional Factory Methods\n\n### .generate({ time }) => id\nReturn a new id instance.  Set any argument to `null` or `undefined` to trigger\nits default behavior.\n\n`time` defaults to the current time.  It can be given either as a `Date` object\nor epoch milliseconds (milliseconds since January 1st, 1970).\nThrow `InvalidEpoch` for times before the epoch or after approximately August 2nd, 10889.\nThis is provided mostly for unit tests.\n\n## Byte Format\nFormat `tttt tttt tttt rrrr rrrr rrrr rrrr rrrr` where:\n- `t` is 4 bits of time\n- `r` is 4 bits of random\n\n# UlidMonotonic\n```es6\nconst { UlidMonotonic } = require('id128');\n```\n\nUlidMonotonic is inspired by the [specification](https://github.com/ulid/spec#monotonicity):\n- collision resistant: 15-bits of random seeded clock sequence plus 64-bits of randomness\n- total ordered: prefixed with millisecond precision timestamp plus 15-bit clock sequence\n- database friendly: fits within a uuid and generally appends to the index\n- human friendly: canonically encodes as a case-insensitive Crockford 32 number\n\nIt is useful when you need to guarantee a process unique id.\n\n## Additional Instance Properties\n\n### time\nReturn a Date object for the epoch milliseconds encoded in the id.\n\n## Additional Factory Methods\n\n### .generate({ time }) => id\nReturn a new id instance.  Set any argument to `null` or `undefined` to trigger\nits default behavior.\n\n`time` defaults to the current time.  It can be given either as a `Date` object\nor epoch milliseconds (milliseconds since January 1st, 1970).  Extra caution is\nrequired since setting a future time and subsequently calling `generate`\nguarantees usage of the clock sequence.\nThrow `InvalidEpoch` for times before the epoch or after approximately August 2nd, 10889.\nThrow `ClockSequenceOverflow` when the clock sequence is exhausted.\nThis is provided mostly for unit tests.\n\n### .reset()\nReturn the clock sequence to its starting position.  This is provided mostly for\nunit tests.\n\n## Byte Format\nFormat `tttt tttt tttt cccc rrrr rrrr rrrr rrrr` where:\n- `t` is 4 bits of time\n- `c` is 4 bits of random-seeded clock sequence\n- `r` is 4 bits of random\n\nMore specifically, the clock sequence is a counter.  When the first id for a new\ntimestamp is generated, the clock sequence is seeded with random bits and the\nleft-most clock sequence bit is set to 0, reserving 2^15 clock ticks.  Whenever\na time from the past seeds the generator, the previous id's time and clock sequence\nare used instead, with the clock sequence incremented by 1.  This guarantees\nstrict local monotonicity and preserves lexical ordering and general randomness.\n\nWithout a seeded time, UlidMonotonic is unlikely to exceed the clock sequence\n(the clock sequence supports generating a new id every 31 nanoseconds). However,\nin the unlikely event of an overflow, id generation is aborted.\n\n# Uuid1\n```es6\nconst { Uuid1 } = require('id128');\n```\n\nUuid1 implements the [RFC 4122 time specification](https://tools.ietf.org/html/rfc4122#section-4.2):\n- time-based: encodes the current millisecond timestamp\n- location-based: encodes the mac address of the machine\n\nWhile this mostly adheres to the spec, there are a few nuances in the handling\nof time.  Instead of encoding time as 100-nanoseconds since the Gregorian epoch,\n48 bits encode milliseconds since the Gregorian epoch time and 12 bits count past\ntime collisions, resetting whenever given a new future time.  There are a few benefits:\n- high precision time is unreliable in the browser so this ensures better precision\n- the max supported date is now around the year 10502 instead of around 5236\n- generating 4096 ids/ms (~4,000,000 ids/s) is wildly unlikely in real world uses\n- in the rare  hi-res overflow, the count simply spills over to the clock sequence\n\n## Additional Instance Properties\n\n### clock_sequence\nReturn the clock sequence encoded in the id.\n\n### hires_time\nReturn the number of prior ids generated while time stood still.\n\n### node\nReturn the MAC address encoded in the id.\n\n### time\nReturn a Date object for the epoch milliseconds encoded in the id.\n\n### variant\nReturn the variant as encoded in the id.  Should be 1.\n\n### version\nReturn the version as encoded in the id.  Should be 1.\n\n## Additional Factory Methods\n\n### .generate({ node, time }) => id\nReturn a new id instance.  Set any argument to `null` or `undefined` to trigger\nits default behavior.\n\n`time` defaults to the current time.  It can be given either as a `Date` object\nor Gregorian milliseconds (milliseconds since October 15th, 1582).  Extra caution\nis required since setting a future time and subsequently calling `generate`\nguarantees usage of the hi-res counter and clock sequence.\nThrow `InvalidEpoch` for times before the Gregorian epoch or after approximately May 17, 10502.\nThis is provided mostly for unit tests.\n\n`node` defaults to the MAC address, or a random multicast address when the MAC\naddress is unavailable.  It can be given as an array of 6 bytes.\n\n### .reset()\nReturn the hi-res counter to its starting position and generate a new random\nclock sequence seed.  This is provided mostly for unit tests.\n\n## Byte Format\nFormat `llll lnnn mmmm vhhh tccc aaaa aaaa aaaa` where:\n- `l` is 4 bits of low millisecond time\n- `n` is 4 bits of hi-res time\n- `m` is 4 bits of mid millisecond time\n- `v` is 4 bits of the version\n- `h` is 4 bits of high millisecond time\n- `t` is 2 bits of the variant followed by 2 bits of the clock sequence\n- `c` is 4 bits of the clock sequence\n- `a` is 4 bits of the machine address\n\n# Uuid4\n```es6\nconst { Uuid4 } = require('id128');\n```\n\nUuid4 implements the [RFC 4122 random uuid specification](https://tools.ietf.org/html/rfc4122#section-4.4):\n\n- 122 random bits\n- 2 bits reserved for the variant (1)\n- 4 bits reserved for the version (4)\n\nIt is useful when you need a well-supported globally unique id.\n\n## Additional Instance Properties\n\n### variant\nReturn the variant as encoded in the id.  Should be 1.\n\n### version\nReturn the version as encoded in the id.  Should be 4.\n\n## Byte Format\nFormat `rrrr rrrr rrrr vrrr trrr rrrr rrrr rrrr` where:\n- `r` is 4 bits of random\n- `v` is 4 bits of the version\n- `t` is 2 bits of the variant followed by 2 bits of random\n\n# Uuid6\n```es6\nconst { Uuid6 } = require('id128');\n```\n\nUuid6 implements this [controversial blog post](https://bradleypeabody.github.io/uuidv6/):\n- time-based: encodes the current millisecond timestamp\n- location-based: encodes the mac address of the machine\n\nThis is essentially the same implementation as Uuid1, however the time bits are\narranged in lexicographical order.  If you're looking for a spacial UUID that\nis optimized for clustered indices, consider Uuid6 as a viable option.\n\n## Additional Instance Properties\n\n### clock_sequence\nReturn the clock sequence encoded in the id.\n\n### hires_time\nReturn the number of prior ids generated while time stood still.\n\n### node\nReturn the MAC address encoded in the id.\n\n### time\nReturn a Date object for the epoch milliseconds encoded in the id.\n\n### variant\nReturn the variant as encoded in the id.  Should be 1.\n\n### version\nReturn the version as encoded in the id.  Should be 6.\n\n## Additional Factory Methods\n\n### .generate({ node, time }) => id\nReturn a new id instance.  Set any argument to `null` or `undefined` to trigger\nits default behavior.\n\n`time` defaults to the current time.  It can be given either as a `Date` object\nor Gregorian milliseconds (milliseconds since October 15th, 1582).  Extra caution\nis required since setting a future time and subsequently calling `generate`\nguarantees usage of the hi-res counter and clock sequence.\nThrow `InvalidEpoch` for times before the Gregorian epoch or after approximately May 17, 10502.\nThis is provided mostly for unit tests.\n\n`node` defaults to the MAC address, or a random multicast address when the MAC\naddress is unavailable.  It can be given as an array of 6 bytes.\n\n### .reset()\nReturn the hi-res counter to its starting position and generate a new random\nclock sequence seed.  This is provided mostly for unit tests.\n\n## Byte Format\nFormat `mmmm mmmm mmmm vnnn tccc aaaa aaaa aaaa` where:\n- `m` is 4 bits of millisecond time\n- `v` is 4 bits of the version\n- `n` is 4 bits of hi-res time\n- `t` is 2 bits of the variant followed by 2 bits of the clock sequence\n- `c` is 4 bits of the clock sequence\n- `a` is 4 bits of the machine address\n\n# UuidNil\n```es6\nconst { UuidNil } = require('id128');\n```\n\nUuidNil implements the [RFC 4122 nil uuid specification](https://tools.ietf.org/html/rfc4122#section-4.1.7):\n\n- 128 bits of glorious 0\n\nIt is useful as placeholder for other 128-bit ids.\n\n## Additional Instance Properties\n\n### variant\nReturn the variant as encoded in the id.  Should be 0.\n\n### version\nReturn the version as encoded in the id.  Should be 0.\n\n## Byte Format\nFormat `0000 0000 0000 v000 t000 0000 0000 0000` where:\n- `0` is 4 bits of 0\n- `v` is 4 bits of the version (also 0)\n- `t` is 2 bits of the variant (also 0) followed by 2 bits of 0\n\n# Uuid\n```es6\nconst { Uuid } = require('id128');\n```\n\nUuid is a factory for generating and decoding UUIDs when the version is unknown\nuntil runtime.  If the version is supported, it will produce UUIDs of the\nappropriate type.  In exchange for the runtime flexibility, there is a necessary\nperformance degradation.  It is recommended to use this for decoding data from\nuncontrolled sources rather than generating new ids.\n\nUuid supports all the same methods as the other ID factories.  All modifications\nto typical behavior are noted below.\n\n## Factory Properties\n\n### versioned_ids\nReturn the factories of all the supported ids.\n\n## Factory Methods\n\n### .construct(bytes) => versioned_id\nReturn a new versioned id instance without validating the bytes.\nReturn a Uuid if an appropriate version does not exist.\n\n### .generate({ version, ... }) => versioned_id\nReturn a new versioned id instance.  All additional arguments are passed through\nto the associated version.\nThrow `UnsupportedVersion` if no associated version exists.\n\n### .MIN({ version }) => versioned_id\nReturn the versioned id instance with the smallest valid value.\nThrow `UnsupportedVersion` if no associated version exists.\n\n### .MAX({ version }) => versioned_id\nReturn the versioned id instance with the largest valid value.\nThrow `UnsupportedVersion` if no associated version exists.\n\n### .fromCanonical(canonical_string) => versioned_id\nDecode a versioned id from its canonical representation.\nReturn a Uuid if an appropriate version does not exist.\nThrow `InvalidEncoding` if the string is undecodable.\n\n### .fromCanonicalTrusted(canonical_string) => versioned_id\nDecode a versioned id from its canonical representation.\nReturn a Uuid if an appropriate version does not exist.\nSkip validation and assume the input is decodable.\n\n### .fromRaw(raw_string) => versioned_id\nDecode a versioned id from its raw representation.\nReturn a Uuid if an appropriate version does not exist.\nThrow `InvalidEncoding` if the string is undecodable.\n\n### .fromRawTrusted(raw_string) => versioned_id\nDecode a versioned id from its raw representation.\nReturn a Uuid if an appropriate version does not exist.\nSkip validation and assume the input is decodable.\n\n# Exceptions\n```es6\nconst { Exception } = require('id128');\n```\nAll exceptions are namespaced under `Exception` for clarity.\n\n## Id128Error\n```es6\nconst { Exception: { Id128Error } } = require('id128');\n```\nBase exception class for generic error catching.\n\n## ClockSequenceOverflow\n```es6\nconst { Exception: { ClockSequenceOverflow } } = require('id128');\n```\nIncrementing the clock sequence is impossible.  Should not happen unless manually seeding `#generate`.\n\n## InvalidBytes\n```es6\nconst { Exception: { InvalidBytes } } = require('id128');\n```\nEncoding something other than 16 bytes.  Likely to happen when encoding untrusted user input.\n\n## InvalidEncoding\n```es6\nconst { Exception: { InvalidEncoding } } = require('id128');\n```\nDecoding an invalid format or non-string object.  Likely to happen when decoding untrusted user input.\n\n## InvalidEpoch\n```es6\nconst { Exception: { InvalidEpoch } } = require('id128');\n```\nGenerating an id with an invalid timestamp.  Should not happen unless manually seeding `#generate`.\n\n## UnsupportedVersion\n```es6\nconst { Exception: { UnsupportedVersion } } = require('id128');\n```\nFailed to find a factory for the desired version.  Likely to happen when decoding untrusted user input.\n\n# Browser Support\n\nThis module supports browser compilation though Webpack/Browserify with a few caveats:\n- Random number generation is optimized for memory usage over speed since only a\nhandful of ids are likely to be generated during a user's session so the overhead\nof generating a page of random values has poor amortized cost.\n- The browser must have native support for `crypto`.  `Math.random` is far too\ninsecure to support as a fallback, especially since the fallback only makes sense\nfor older browsers with proven security holes.  `msCrypto` is not a supported\nfallback due to many of the other required features.\n- The browser must support:\n\t* classes\n\t* closures\n\t* `const` and `let`\n\t* `Uint8Array`\n\t* `Symbol`\n\nThis library is intended for modern browsers that keep pace with Javascript's\ngrowing ecosystem.  I philosophically object to supporting efforts of companies\nto pour more money into broken browsers that only cause headaches for developers\nto support.  I expect these caveats to be unnecessary within the next 5 years.\n\nAll that said, please notify me of any issues with modern browsers and I'll do\nmy best to support you.\n\n# Typescript Support\n\nThis module includes Typescript bindings for all primary usage patterns.\nI'd like to highlight some design decisions:\n\n## Id Types and Factory Types\nEach factory is exported as an instance using the same name as the type of id\nit produces.  In Javascript, this is desirable as it provides a uniform interface\nregardless of the implementation.  However, this complicates the Typescript\ntype imports.\n\nFor simple cases, like constructing an id and passing it around the program,\nthis will behave exactly as desired:\n```\nimport { Ulid } from 'id128'\n\nconst id: Ulid = Ulid.generate()\n```\n\nWhen you need to check the type of the id, you should use the `type` attribute:\n```\nimport { Ulid } from 'id128'\n\nconst id: Ulid = Ulid.generate()\nif (id instanceof Ulid.type) { ... }\n```\n\nIf you wish to pass around the factory itself, you can import the factory type:\n```\nimport { Ulid } from 'id128'\nimport type { UlidFactory } from 'id128'\n\nfunction doSomething(factory: UlidFactory) { ... }\ndoSomething(Ulid)\n```\n\nFinally, if you need to operate on any id or id factory, you can import base types:\n```\nimport type { Id, AnyIdFactory } from 'id128'\n\nfunction makeOne(factory: AnyIdFactory): Id {\n\treturn factory.generate()\n}\n```\n\n## Exception Handling\nException classes are designed to be checked using `instanceof`.  Unfortunately,\nTypescript broke `instanceof` `Error` support for a more compliant compilation.\nFortunately, the included exceptions bypass the issues caused by inheriting from\nthe native `Error` by never overriding the constructor and implementing `name`\nas a readonly getter,  As a consequence, the exceptions actually violate the\nstandard `Error` interface, but they fulfill the standard `Function` interface.\nTherefore, you can safely use `instanceof` as intended:\n```\nimport { UlidMonotonic } from 'id128'\nimport { Exception } from 'id128'\n\ntry { UlidMonotonic.generate() }\ncatch (err) {\n\tif (err instanceof Exception.ClockSequenceOverflow ) { ... }\n}\n```\n\n# Motivation\n\nOriginally, I was looking for an id that is independent of the database, but plays\nnice with database indices and data types.  Most databases have built-in support\nfor storing UUIDs efficiently, but UUID v4 does not cluster well and the other UUIDs\nrequire bit manipulation to get good performance, which will likely cause future\nmaintenance headaches.\n\nAfter a bit of research, ULID was determined to nicely solve the problem.  However,\nthe javascript implementation had 2 major issues:\n1. lacks database support\n2. it's slow, which in a single-threaded Node server is deadly\n\nI considered sending in a patch, however I saw an opportunity for a more expressive\ninterface, which is typically a bit harder to modify once a project is in wide use.\nThere was also a clear pattern for encoding 128-bit ids into various formats,\nwhich seems generally useful.\n\nUltimately, this library strives to be:\n- secure: uses cryptographic randomness to ensure general uniqueness\n- performant: currently one of the fastest id generators available\n- maintainable: heavily tested isolated code with a consistent interface\n- extensible: modular design to easily add new ids and new encodings\n\n# Tests\n\nTo run the tests:\n```bash\nnpm install\nnpm run test-all\n```\n\n# Benchmarks\n\nCompetitive benchmarks have been moved to [benchmark-guid](https://github.com/aarondcohen/benchmark-guid)\n\nTo run the benchmarks:\n```bash\nnpm install\nnpm run benchmark\n```\n\n```\nPlatform info:\n==============\n   Darwin 18.2.0 x64\n   Node.JS: 15.0.0\n   V8: 8.6.395.16-node.15\n   Intel(R) Core(TM) i7-4578U CPU @ 3.00GHz × 4\n\nUlid\n====\n   generate:                  (4,590,833rps)   (avg: 217ns)\n   MIN:                      (12,491,186rps)   (avg: 80ns)\n   MAX:                      (12,669,223rps)   (avg: 78ns)\n   fromCanonical:             (1,707,717rps)   (avg: 585ns)\n   fromCanonicalTrusted:      (2,078,278rps)   (avg: 481ns)\n   fromRaw:                   (1,483,373rps)   (avg: 674ns)\n   fromRawTrusted:            (1,979,964rps)   (avg: 505ns)\n   toCanonical:               (3,256,155rps)   (avg: 307ns)\n   toRaw:                     (6,012,244rps)   (avg: 166ns)\n\nUlidMonotonic\n=============\n   generate:                  (3,787,685rps)   (avg: 264ns)\n   MIN:                       (6,306,928rps)   (avg: 158ns)\n   MAX:                       (6,301,217rps)   (avg: 158ns)\n   fromCanonical:             (1,423,104rps)   (avg: 702ns)\n   fromCanonicalTrusted:      (1,722,958rps)   (avg: 580ns)\n   fromRaw:                   (1,381,296rps)   (avg: 723ns)\n   fromRawTrusted:            (1,698,639rps)   (avg: 588ns)\n   toCanonical:               (3,205,394rps)   (avg: 311ns)\n   toRaw:                     (5,774,288rps)   (avg: 173ns)\n\nUuid1\n=====\n   generate:                  (4,984,699rps)   (avg: 200ns)\n   MIN:                      (12,888,384rps)   (avg: 77ns)\n   MAX:                      (12,817,435rps)   (avg: 78ns)\n   fromCanonical:             (1,226,007rps)   (avg: 815ns)\n   fromCanonicalTrusted:      (1,578,429rps)   (avg: 633ns)\n   fromRaw:                   (1,306,295rps)   (avg: 765ns)\n   fromRawTrusted:            (1,626,095rps)   (avg: 614ns)\n   toCanonical:               (5,859,714rps)   (avg: 170ns)\n   toRaw:                     (5,973,139rps)   (avg: 167ns)\n\nUuid4\n=====\n   generate:                  (6,492,849rps)   (avg: 154ns)\n   MIN:                       (6,400,528rps)   (avg: 156ns)\n   MAX:                       (6,617,714rps)   (avg: 151ns)\n   fromCanonical:             (1,286,561rps)   (avg: 777ns)\n   fromCanonicalTrusted:      (1,625,362rps)   (avg: 615ns)\n   fromRaw:                   (1,313,004rps)   (avg: 761ns)\n   fromRawTrusted:            (1,672,463rps)   (avg: 597ns)\n   toCanonical:               (6,103,543rps)   (avg: 163ns)\n   toRaw:                     (6,235,448rps)   (avg: 160ns)\n\nUuid6\n=====\n   generate:                  (3,466,357rps)   (avg: 288ns)\n   MIN:                       (5,244,292rps)   (avg: 190ns)\n   MAX:                       (5,151,746rps)   (avg: 194ns)\n   fromCanonical:             (1,324,905rps)   (avg: 754ns)\n   fromCanonicalTrusted:      (1,676,541rps)   (avg: 596ns)\n   fromRaw:                   (1,357,353rps)   (avg: 736ns)\n   fromRawTrusted:            (1,717,530rps)   (avg: 582ns)\n   toCanonical:               (5,061,822rps)   (avg: 197ns)\n   toRaw:                     (4,839,125rps)   (avg: 206ns)\n\nUuidNil\n=======\n   generate:                  (9,312,932rps)   (avg: 107ns)\n   MIN:                       (5,158,703rps)   (avg: 193ns)\n   MAX:                       (8,795,275rps)   (avg: 113ns)\n   fromCanonical:             (1,293,946rps)   (avg: 772ns)\n   fromCanonicalTrusted:      (1,629,605rps)   (avg: 613ns)\n   fromRaw:                   (1,472,042rps)   (avg: 679ns)\n   fromRawTrusted:            (1,780,904rps)   (avg: 561ns)\n   toCanonical:               (5,169,323rps)   (avg: 193ns)\n   toRaw:                     (5,196,170rps)   (avg: 192ns)\n\nUuid processing Uuid1\n=====================\n   generate:                  (4,159,340rps)   (avg: 240ns)\n   MIN:                       (4,877,918rps)   (avg: 205ns)\n   MAX:                       (4,907,348rps)   (avg: 203ns)\n   fromCanonical:             (1,045,214rps)   (avg: 956ns)\n   fromCanonicalTrusted:      (1,255,223rps)   (avg: 796ns)\n   fromRaw:                   (1,021,436rps)   (avg: 979ns)\n   fromRawTrusted:            (1,268,213rps)   (avg: 788ns)\n\nUuid processing Uuid4\n=====================\n   generate:                  (5,695,823rps)   (avg: 175ns)\n   MIN:                       (4,886,337rps)   (avg: 204ns)\n   MAX:                       (4,907,325rps)   (avg: 203ns)\n   fromCanonical:             (1,047,372rps)   (avg: 954ns)\n   fromCanonicalTrusted:      (1,292,729rps)   (avg: 773ns)\n   fromRaw:                   (1,031,590rps)   (avg: 969ns)\n   fromRawTrusted:            (1,266,122rps)   (avg: 789ns)\n\nUuid processing Uuid6\n=====================\n   generate:                  (4,122,279rps)   (avg: 242ns)\n   MIN:                       (4,744,102rps)   (avg: 210ns)\n   MAX:                       (4,860,271rps)   (avg: 205ns)\n   fromCanonical:             (1,066,004rps)   (avg: 938ns)\n   fromCanonicalTrusted:      (1,298,925rps)   (avg: 769ns)\n   fromRaw:                   (1,053,871rps)   (avg: 948ns)\n   fromRawTrusted:            (1,286,373rps)   (avg: 777ns)\n\nUuid processing UuidNil\n=======================\n   generate:                  (8,140,742rps)   (avg: 122ns)\n   MIN:                       (4,717,779rps)   (avg: 211ns)\n   MAX:                       (8,261,012rps)   (avg: 121ns)\n   fromCanonical:             (1,052,765rps)   (avg: 949ns)\n   fromCanonicalTrusted:      (1,285,968rps)   (avg: 777ns)\n   fromRaw:                   (1,130,468rps)   (avg: 884ns)\n   fromRawTrusted:            (1,312,878rps)   (avg: 761ns)\n```\n\n# Acknowledgments\n\nMuch of this library would not exist without the great work and documentation of\nother engineers.  In particular:\n\n- [ksuid](https://github.com/segmentio/ksuid): an in-depth exploration of the guid nuances\n- [ulid](https://github.com/ulid/javascript): an elegant solution to a persistent problem\n- [uuid-random](https://github.com/jchook/uuid-random): allocating pages of randomness is by far the biggest performance factor\n\nAlso, thank you:\n- [ruleb](https://github.com/ruleb): researching and patching worker support\n\n# Contributing\n\nFeel free to make a branch and send a pull request through [github](https://github.com/aarondcohen/id128)\n\n# Issues\n\nPlease report any issues or bugs through [github](https://github.com/aarondcohen/id128/issues)\n"
  },
  {
    "path": "benchmark/basics.js",
    "content": "const Benchmarkify = require('benchmarkify');\nconst Id128 = require('../');\nconst { IdFactory } = require('../utils');\nconst { VersionedIdFactory } = require('../utils');\n\nconst benchmark = new Benchmarkify(\"Basics\").printHeader();\nconst suites_by_name = Object.fromEntries([\n\t'generate',\n\t'MIN',\n\t'MAX',\n\t'fromCanonical',\n\t'fromCanonicalTrusted',\n\t'fromRaw',\n\t'fromRawTrusted',\n\t'toCanonical',\n\t'toRaw'\n].map((name) => [name, benchmark.createSuite(name, { cycles: 1000000 })]));\n\nObject.values(Id128)\n\t.filter(x => x instanceof IdFactory)\n\t.filter(x => !(x instanceof VersionedIdFactory))\n\t.sort((l, r)  => l.name.localeCompare(r.name))\n\t.forEach((id_type) => {\n\t\tconst name = id_type.name;\n\t\tconst id = id_type.generate();\n\t\tconst canonical = id.toCanonical();\n\t\tconst raw = id.toRaw();\n\n\t\tsuites_by_name.generate.add(name, () => id_type.generate());\n\t\tsuites_by_name.MIN.add(name, () => id_type.MIN());\n\t\tsuites_by_name.MAX.add(name, () => id_type.MAX());\n\t\tsuites_by_name.fromCanonical.add(name, () => id_type.fromCanonical(canonical));\n\t\tsuites_by_name.fromCanonicalTrusted.add(name, () => id_type.fromCanonicalTrusted(canonical));\n\t\tsuites_by_name.fromRaw.add(name, () => id_type.fromRaw(raw));\n\t\tsuites_by_name.fromRawTrusted.add(name, () => id_type.fromRawTrusted(raw));\n\t\tsuites_by_name.toCanonical.add(name, () => id.toCanonical());\n\t\tsuites_by_name.toRaw.add(name, () => id.toRaw());\n\t});\n\nbenchmark.run(Object.values(suites_by_name));\n"
  },
  {
    "path": "benchmark/factory-uuid.js",
    "content": "const Benchmarkify = require('benchmarkify');\nconst Id128 = require('../');\n\nconst benchmark = new Benchmarkify(\"UUID Processing\").printHeader();\nconst suites_by_name = Object.fromEntries([\n\t'generate',\n\t'MIN',\n\t'MAX',\n\t'fromCanonical',\n\t'fromCanonicalTrusted',\n\t'fromRaw',\n\t'fromRawTrusted',\n].map((name) => [name, benchmark.createSuite(name, { cycles: 100000 })]));\n\nconst factory = Id128.Uuid;\nfactory.versioned_ids\n\t.sort((l, r)  => l.name.localeCompare(r.name))\n\t.forEach((id_type) => {\n\t\tconst name = id_type.name;\n\t\tconst id = id_type.generate();\n\t\tconst canonical = id.toCanonical();\n\t\tconst raw = id.toRaw();\n\t\tconst type = { version: id.version };\n\n\t\tsuites_by_name.generate.add(name, () => factory.generate(type));\n\t\tsuites_by_name.MIN.add(name, () => factory.MIN(type));\n\t\tsuites_by_name.MAX.add(name, () => factory.MAX(type));\n\t\tsuites_by_name.fromCanonical.add(name, () => factory.fromCanonical(canonical));\n\t\tsuites_by_name.fromCanonicalTrusted.add(name, () => factory.fromCanonicalTrusted(canonical));\n\t\tsuites_by_name.fromRaw.add(name, () => factory.fromRaw(raw));\n\t\tsuites_by_name.fromRawTrusted.add(name, () => factory.fromRawTrusted(raw));\n\t});\n\nbenchmark.run(Object.values(suites_by_name));\n"
  },
  {
    "path": "benchmark/memory.js",
    "content": "const ByteArray = require('common/byte-array');\n\nlet count = 0\nlet result = null;\nlet now = new Date;\ntry {\n\twhile (++count) {\n\t\tresult = ByteArray.generateRandomFilled();\n\t\tresult = null\n\n\t\tif (!(count % 10000000)) {\n\t\t\tglobal.gc && global.gc();\n\t\t\tconst used = process.memoryUsage();\n\t\t\tconsole.log(`Runs: ${count}`)\n\t\t\tfor (let key in used) {\n\t\t\t\tconsole.log(`${key} ${Math.round(used[key] / 1024 * 100) / 100} KB`);\n\t\t\t}\n\t\t}\n\t}\n} catch (err) {\n\tconst end = new Date;\n\tconsole.log(err);\n\tconsole.log([String(count).padStart(12), ...result].join(':'));\n\tconsole.log(`Time: ${end - now}, ${count/(end - now)}ops/ms`);\n}\n"
  },
  {
    "path": "benchmark/stats.js",
    "content": "const Benchmarkify = require('benchmarkify');\nconst Id128 = require('../');\nconst { Uuid } = Id128;\n\nconst benchmark = new Benchmarkify(\"Stats\").printHeader();\n\nconst id_suites = [\n\tId128.Ulid,\n\tId128.UlidMonotonic,\n\tId128.Uuid1,\n\tId128.Uuid4,\n\tId128.Uuid6,\n\tId128.UuidNil,\n].map((id_type) => {\n\tconst id = id_type.generate();\n\tconst canonical = id.toCanonical();\n\tconst raw = id.toRaw();\n\tconst suite = benchmark.createSuite(id_type.name, { cycles: 1000000 });\n\n\tsuite.add('generate:', () => id_type.generate());\n\tsuite.add('MIN:', () => id_type.MIN());\n\tsuite.add('MAX:', () => id_type.MAX());\n\tsuite.add('fromCanonical:', () => id_type.fromCanonical(canonical));\n\tsuite.add('fromCanonicalTrusted:', () => id_type.fromCanonicalTrusted(canonical));\n\tsuite.add('fromRaw:', () => id_type.fromRaw(raw));\n\tsuite.add('fromRawTrusted:', () => id_type.fromRawTrusted(raw));\n\tsuite.add('toCanonical:', () => id.toCanonical());\n\tsuite.add('toRaw:', () => id.toRaw());\n\n\treturn suite;\n});\n\nconst uuid_suites = Uuid.versioned_ids\n\t.sort((l, r)  => l.name.localeCompare(r.name))\n\t.map((id_type) => {\n\t\tconst id = id_type.generate();\n\t\tconst canonical = id.toCanonical();\n\t\tconst raw = id.toRaw();\n\t\tconst type = { version: id.version };\n\n\t\tconst suite = benchmark.createSuite(\n\t\t\t`Uuid processing ${id_type.name}`,\n\t\t\t{ cycles: 1000000 }\n\t\t);\n\n\t\tsuite.add('generate:', () => Uuid.generate(type));\n\t\tsuite.add('MIN:', () => Uuid.MIN(type));\n\t\tsuite.add('MAX:', () => Uuid.MAX(type));\n\t\tsuite.add('fromCanonical:', () => Uuid.fromCanonical(canonical));\n\t\tsuite.add('fromCanonicalTrusted:', () => Uuid.fromCanonicalTrusted(canonical));\n\t\tsuite.add('fromRaw:', () => Uuid.fromRaw(raw));\n\t\tsuite.add('fromRawTrusted:', () => Uuid.fromRawTrusted(raw));\n\n\t\treturn suite;\n\t});\n\nbenchmark.run(id_suites.concat(uuid_suites));\n"
  },
  {
    "path": "index.d.ts",
    "content": "/* eslint-disable @typescript-eslint/no-empty-interface */\nexport {};\n\n// Utility Types\n\ninterface ConstructorOf<C> {\n\tnew(...args: any[]): C;\n}\n\n// Id Types\n\nexport interface Id {\n\treadonly bytes: Uint8Array;\n\treadonly [Symbol.toStringTag]: string;\n\n\tclone(): this;\n\n\ttoCanonical(): string;\n\ttoRaw(): string;\n\n\tcompare(rhs: Id): number;\n\tequal(rhs: Id): boolean;\n}\n\nexport interface Uuid extends Id {\n\treadonly variant: number;\n\treadonly version: number;\n}\n\nexport interface Ulid extends Id {\n\treadonly time: Date;\n}\n\nexport interface UlidMonotonic extends Id {\n\treadonly time: Date;\n}\n\nexport interface Uuid1 extends Uuid {\n\treadonly clock_sequence: number;\n\treadonly hires_time: number;\n\treadonly node: Uint8Array;\n\treadonly time: Date;\n}\n\nexport interface Uuid4 extends Uuid {}\n\nexport interface Uuid6 extends Uuid {\n\treadonly clock_sequence: number;\n\treadonly hires_time: number;\n\treadonly node: Uint8Array;\n\treadonly time: Date;\n}\n\nexport interface UuidNil extends Uuid {}\n\n// Id Factories\n\ninterface IdFactory<T> {\n\treadonly name: string;\n\treadonly type: ConstructorOf<T>;\n\n\tconstruct(bytes: Uint8Array): T;\n\tgenerate(options?: {}): T;\n\tMIN(options?: {}): T;\n\tMAX(options?: {}): T;\n\n\tfromCanonical(canonical: string): T;\n\tfromCanonicalTrusted(canonical: string): T;\n\tfromRaw(raw: string): T;\n\tfromRawTrusted(raw: string): T;\n\n\ttoCanonical(id: T): string;\n\ttoRaw(id: T): string;\n\n\tcompare(lhs: Id, rhs: Id): number;\n\tequal(lhs: Id, rhs: Id): boolean;\n\n\tisCanonical(canonical: string): boolean;\n\tisRaw(raw: string): boolean;\n}\n\ninterface VersionedIdFactory<T> extends IdFactory<T> {\n\treadonly versioned_ids: Array<IdFactory<T>>;\n\n\tMIN(options: VersionOption): T;\n\tMAX(options: VersionOption): T;\n}\n\ninterface NodeOption {\n\tnode?: Uint8Array | null;\n}\n\ninterface TimeOption {\n\ttime?: Date | number | null;\n}\n\ninterface VersionOption {\n\tversion: number;\n}\n\nexport type AnyIdFactory = IdFactory<Id>;\n\nexport interface UlidFactory extends IdFactory<Ulid> {\n\tgenerate(options?: TimeOption): Ulid;\n}\n\nexport interface UlidMonotonicFactory extends IdFactory<UlidMonotonic> {\n\tgenerate(options?: TimeOption): UlidMonotonic;\n}\n\nexport interface UuidFactory extends VersionedIdFactory<Uuid> {\n\tgenerate(options: NodeOption & TimeOption & VersionOption): Uuid;\n}\n\nexport interface Uuid1Factory extends IdFactory<Uuid1> {\n\tgenerate(options?: NodeOption & TimeOption): Uuid1;\n}\n\nexport interface Uuid4Factory extends IdFactory<Uuid4> {\n\tgenerate(options?: {}): Uuid4;\n}\n\nexport interface Uuid6Factory extends IdFactory<Uuid6> {\n\tgenerate(options?: NodeOption & TimeOption): Uuid6;\n}\n\nexport interface UuidNilFactory extends IdFactory<UuidNil> {\n\tgenerate(options?: {}): UuidNil;\n}\n\n// Errors\n\n// NOTE: Actually extends Error, but typescript breaks instanceof support\nexport interface Id128Error extends Function {\n\treadonly name: string;\n\tmessage: string;\n\tstack?: string;\n}\nexport interface ClockSequenceOverflow extends Id128Error {}\nexport interface InvalidBytes extends Id128Error {}\nexport interface InvalidEncoding extends Id128Error {}\nexport interface InvalidEpoch extends Id128Error {}\nexport interface UnsupportedVersion extends Id128Error {}\n\n// Exported Functions\n\nexport function idCompare(lhs: Id, rhs: Id): number;\nexport function idEqual(lhs: Id, rhs: Id): boolean;\n\n// Exported Constants\n\nexport const Ulid: UlidFactory;\nexport const UlidMonotonic: UlidMonotonicFactory;\nexport const Uuid: UuidFactory;\nexport const Uuid1: Uuid1Factory;\nexport const Uuid4: Uuid4Factory;\nexport const Uuid6: Uuid6Factory;\nexport const UuidNil: UuidNilFactory;\n\nexport namespace Exception {\n\tconst Id128Error: ConstructorOf<Id128Error>;\n\tconst ClockSequenceOverflow: ConstructorOf<ClockSequenceOverflow>;\n\tconst InvalidBytes: ConstructorOf<InvalidBytes>;\n\tconst InvalidEncoding: ConstructorOf<InvalidEncoding>;\n\tconst InvalidEpoch: ConstructorOf<InvalidEpoch>;\n\tconst UnsupportedVersion: ConstructorOf<UnsupportedVersion>;\n}\n"
  },
  {
    "path": "index.js",
    "content": "const { Ulid } = require('./src/id/ulid');\nconst { UlidMonotonic } = require('./src/id/ulid-monotonic');\nconst { Uuid } = require('./src/id/uuid');\nconst { Uuid1 } = require('./src/id/uuid-1');\nconst { Uuid4 } = require('./src/id/uuid-4');\nconst { Uuid6 } = require('./src/id/uuid-6');\nconst { UuidNil } = require('./src/id/uuid-nil');\n\nconst Crockford32Coder = require('./src/coder/crockford32');\nconst HexCoder = require('./src/coder/hex');\nconst UuidCoder = require('./src/coder/uuid');\n\nconst { IdFactory } = require('./src/factory/id');\nconst { VersionedIdFactory } = require('./src/factory/versioned-id');\nconst Exception = require('./src/common/exception');\n\nconst namespace = {\n\tidCompare: function(lhs, rhs) { return lhs.compare(rhs); },\n\tidEqual: function(lhs, rhs) { return lhs.equal(rhs); },\n\tException,\n\tUlid: new IdFactory({\n\t\tid: Ulid,\n\t\tcanonical_coder: Crockford32Coder,\n\t\traw_coder: HexCoder,\n\t}),\n\tUlidMonotonic: new IdFactory({\n\t\tid: UlidMonotonic,\n\t\tcanonical_coder: Crockford32Coder,\n\t\traw_coder: HexCoder,\n\t}),\n\tUuid: new VersionedIdFactory({\n\t\tabstract_id: Uuid,\n\t\tversioned_ids: [\n\t\t\tUuid1,\n\t\t\tUuid4,\n\t\t\tUuid6,\n\t\t\tUuidNil,\n\t\t],\n\t\tcanonical_coder: UuidCoder,\n\t\traw_coder: HexCoder,\n\t}),\n};\n\nnamespace.Uuid.versioned_ids.reduce(\n\t(ns, uuid) => Object.assign(ns, {[uuid.name]: uuid}),\n\tnamespace\n);\n\nmodule.exports = namespace;\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"id128\",\n\t\"description\": \"Collection of 128-bit Id generators\",\n\t\"version\": \"1.6.6\",\n\t\"author\": \"Aaron Cohen <aarondcohen@gmail.com>\",\n\t\"license\": \"MIT\",\n\t\"main\": \"index.js\",\n\t\"types\": \"index.d.ts\",\n\t\"files\": [\n\t\t\"index.d.ts\",\n\t\t\"index.js\",\n\t\t\"src/\",\n\t\t\"utils.js\"\n\t],\n\t\"homepage\": \"https://github.com/aarondcohen/id128#id128\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/aarondcohen/id128.git\"\n\t},\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/aarondcohen/id128/issues\"\n\t},\n\t\"browser\": {\n\t\t\"./src/common/machine.js\": \"./src/common/fake-machine.js\",\n\t\t\"./src/common/random-bytes.js\": \"./src/common/random-bytes-browser.js\"\n\t},\n\t\"scripts\": {\n\t\t\"benchmark\": \"NODE_PATH='./src/' node benchmark/stats.js\",\n\t\t\"call\": \"NODE_PATH='./src/' node\",\n\t\t\"dtslint\": \"dtslint types\",\n\t\t\"test\": \"NODE_PATH='./src/' mocha\",\n\t\t\"test-all\": \"NODE_PATH='./src/' mocha test/*\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=v6.9.0\"\n\t},\n\t\"devDependencies\": {\n\t\t\"benchmarkify\": \"github:aarondcohen/benchmarkify\",\n\t\t\"chai\": \"*\",\n\t\t\"dtslint\": \"^3.4.1\",\n\t\t\"mocha\": \"*\",\n\t\t\"sinon\": \"*\"\n\t},\n\t\"keywords\": [\n\t\t\"128-bit\",\n\t\t\"crockford32\",\n\t\t\"guid\",\n\t\t\"id\",\n\t\t\"monotonic\",\n\t\t\"random\",\n\t\t\"rfc-4122\",\n\t\t\"rfc4122\",\n\t\t\"uid\",\n\t\t\"ulid\",\n\t\t\"unique\",\n\t\t\"universal\",\n\t\t\"uuid\",\n\t\t\"uuid-v1\",\n\t\t\"uuid-v4\",\n\t\t\"uuid-v6\",\n\t\t\"uuid1\",\n\t\t\"uuid4\",\n\t\t\"uuid6\",\n\t\t\"uuidv1\",\n\t\t\"uuidv4\",\n\t\t\"uuidv6\"\n\t]\n}\n"
  },
  {
    "path": "src/coder/base.js",
    "content": "'use strict';\n\nconst {\n\tInvalidEncoding,\n\tInvalidBytes,\n} = require('../common/exception');\n\nconst _valid_encoding_pattern = Symbol('valid_encoding_pattern');\n\nclass BaseCoder {\n\tconstructor({\n\t\tvalid_encoding_pattern,\n\t} = {}) {\n\t\tthis[_valid_encoding_pattern] = valid_encoding_pattern;\n\t}\n\n\tdecode(encoding) {\n\t\tif (this.isValidEncoding(encoding)) {\n\t\t\treturn this.decodeTrusted(encoding);\n\t\t}\n\t\telse {\n\t\t\tthrow new InvalidEncoding(`Encoding [${encoding}] does not satisfy ${this[_valid_encoding_pattern]}`);\n\t\t}\n\t}\n\n\tdecodeTrusted(encoding) { return ByteArray.generateRandomFilled() }\n\n\tencode(bytes) {\n\t\tif (this.isValidBytes(bytes)) {\n\t\t\treturn this.encodeTrusted(bytes);\n\t\t}\n\t\telse {\n\t\t\tthrow new InvalidBytes('Requires a 16-byte Uint8Array');\n\t\t}\n\n\t}\n\n\tencodeTrusted(bytes) { return '' }\n\n\tisValidBytes(bytes) {\n\t\treturn true\n\t\t\t&& (bytes instanceof Uint8Array)\n\t\t\t&& bytes.length === 16;\n\t}\n\n\tisValidEncoding(encoding) {\n\t\treturn true\n\t\t\t&& (typeof encoding === 'string' || encoding instanceof String)\n\t\t\t&& this[_valid_encoding_pattern].test(encoding);\n\t}\n}\n\nmodule.exports = { BaseCoder };\n"
  },
  {
    "path": "src/coder/crockford32.js",
    "content": "'use strict';\n\nconst { BaseCoder } = require('./base');\n\nconst ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';\nconst MAX_QUINTET = 0b11111;\n\nconst CHAR_TO_QUINTET = Array.from(ALPHABET).reduce(\n\t(acc, chr, idx) => (acc[chr] = acc[chr.toLowerCase()] = idx, acc),\n\t{\n\t\t'I': ALPHABET.indexOf('1'),\n\t\t'i': ALPHABET.indexOf('1'),\n\t\t'L': ALPHABET.indexOf('1'),\n\t\t'l': ALPHABET.indexOf('1'),\n\t\t'O': ALPHABET.indexOf('0'),\n\t\t'o': ALPHABET.indexOf('0'),\n\t\t'U': ALPHABET.indexOf('V'),\n\t\t'u': ALPHABET.indexOf('V'),\n\t}\n);\nconst QUINTET_TO_CHAR = Array.from(ALPHABET);\n\nfunction _charToQuintet(chr) {\n\treturn CHAR_TO_QUINTET[chr];\n}\n\nfunction _quintetToChar(quintet) {\n\treturn QUINTET_TO_CHAR[quintet & MAX_QUINTET];\n}\n\nclass Crockford32Coder extends BaseCoder {\n\tconstructor() {\n\t\tsuper({\n\t\t\tvalid_encoding_pattern: /^[0-7][^\\W_]{25}$/,\n\t\t});\n\t}\n\n\tdecodeTrusted(encoding) {\n\t\tconst bytes = new Uint8Array(16);\n\t\tconst quintets = [];\n\n\t\tfor (let idx = 0, end = encoding.length; idx < end; ++idx) {\n\t\t\tquintets.push(_charToQuintet(encoding[idx]));\n\t\t}\n\n\t\t//Note: unrolled for performance\n\t\tbytes[0] = quintets[0] << 5 | quintets[1];\n\n\t\tbytes[1] = quintets[2] << 3 | quintets[3] >> 2;\n\t\tbytes[2] = quintets[3] << 6 | quintets[4] << 1 | quintets[5] >> 4;\n\t\tbytes[3] = quintets[5] << 4 | quintets[6] >> 1;\n\t\tbytes[4] = quintets[6] << 7 | quintets[7] << 2 | quintets[8] >> 3;\n\t\tbytes[5] = quintets[8] << 5 | quintets[9];\n\n\t\tbytes[6] = quintets[10] << 3 | quintets[11] >> 2;\n\t\tbytes[7] = quintets[11] << 6 | quintets[12] << 1 | quintets[13] >> 4;\n\t\tbytes[8] = quintets[13] << 4 | quintets[14] >> 1;\n\t\tbytes[9] = quintets[14] << 7 | quintets[15] << 2 | quintets[16] >> 3;\n\t\tbytes[10] = quintets[16] << 5 | quintets[17];\n\n\t\tbytes[11] = quintets[18] << 3 | quintets[19] >> 2;\n\t\tbytes[12] = quintets[19] << 6 | quintets[20] << 1 | quintets[21] >> 4;\n\t\tbytes[13] = quintets[21] << 4 | quintets[22] >> 1;\n\t\tbytes[14] = quintets[22] << 7 | quintets[23] << 2 | quintets[24] >> 3;\n\t\tbytes[15] = quintets[24] << 5 | quintets[25];\n\n\t\treturn bytes;\n\t}\n\n\tencodeTrusted(bytes) {\n\t\t//Note: unrolled for performance\n\t\tlet quintets = [\n\t\t\t(bytes[0] >> 5),\n\t\t\t(bytes[0]),\n\n\t\t\t(bytes[1] >> 3),\n\t\t\t(bytes[1] << 2 | bytes[2] >> 6),\n\t\t\t(bytes[2] >> 1),\n\t\t\t(bytes[2] << 4 | bytes[3] >> 4),\n\t\t\t(bytes[3] << 1 | bytes[4] >> 7),\n\t\t\t(bytes[4] >> 2),\n\t\t\t(bytes[4] << 3 | bytes[5] >> 5),\n\t\t\t(bytes[5]),\n\n\t\t\t(bytes[6] >> 3),\n\t\t\t(bytes[6] << 2 | bytes[7] >> 6),\n\t\t\t(bytes[7] >> 1),\n\t\t\t(bytes[7] << 4 | bytes[8] >> 4),\n\t\t\t(bytes[8] << 1 | bytes[9] >> 7),\n\t\t\t(bytes[9] >> 2),\n\t\t\t(bytes[9] << 3 | bytes[10] >> 5),\n\t\t\t(bytes[10]),\n\n\t\t\t(bytes[11] >> 3),\n\t\t\t(bytes[11] << 2 | bytes[12] >> 6),\n\t\t\t(bytes[12] >> 1),\n\t\t\t(bytes[12] << 4 | bytes[13] >> 4),\n\t\t\t(bytes[13] << 1 | bytes[14] >> 7),\n\t\t\t(bytes[14] >> 2),\n\t\t\t(bytes[14] << 3 | bytes[15] >> 5),\n\t\t\t(bytes[15]),\n\t\t];\n\n\t\t//Note: Massive performance losses occured when\n\t\t// using the more legible Array.map and Array.join\n\t\tlet encoding = '';\n\t\tfor (let idx = 0, end = quintets.length; idx < end; ++idx) {\n\t\t\tencoding += _quintetToChar(quintets[idx]);\n\t\t}\n\t\treturn encoding;\n\t}\n}\n\nmodule.exports = new Crockford32Coder;\n"
  },
  {
    "path": "src/coder/hex.js",
    "content": "'use strict';\n\nconst { BaseCoder } = require('./base');\n\nconst ALPHABET = '0123456789ABCDEF';\n\nconst BYTE_TO_HEX = Array\n\t.from({ length: ALPHABET.length * ALPHABET.length })\n\t.map((_, key) => (\n\t\t''\n\t\t+ ALPHABET.charAt(key / ALPHABET.length)\n\t\t+ ALPHABET.charAt(key % ALPHABET.length)\n\t));\n\nconst HEX_TO_BYTE = Array.from(ALPHABET).reduce(\n\t(mapping, hex, idx) => Object.assign(mapping, {\n\t\t[hex.toUpperCase()]: idx,\n\t\t[hex.toLowerCase()]: idx,\n\t}),\n\tObject.create(null)\n);\n\nclass HexCoder extends BaseCoder {\n\tconstructor() {\n\t\tsuper({\n\t\t\tvalid_encoding_pattern: /^[0-9A-Fa-f]{32}$/,\n\t\t});\n\t}\n\n\tdecodeTrusted(encoding) {\n\t\tlet bytes = new Uint8Array(16);\n\n\t\tfor (\n\t\t\tlet\n\t\t\t\tdst = 0,\n\t\t\t\thi_hex = true,\n\t\t\t\tsrc = 0,\n\t\t\t\tend = encoding.length;\n\t\t\tsrc < end;\n\t\t\t++src\n\t\t) {\n\t\t\tconst hex = encoding[src];\n\t\t\tif (hi_hex) {\n\t\t\t\tbytes[dst] = HEX_TO_BYTE[hex] << 4;\n\t\t\t} else {\n\t\t\t\tbytes[dst++] |= HEX_TO_BYTE[hex];\n\t\t\t}\n\t\t\thi_hex = !hi_hex;\n\t\t}\n\n\t\treturn bytes;\n\t}\n\n\tencodeTrusted(bytes) {\n\t\tlet encoding = '';\n\t\tfor (let idx = 0, end = bytes.length; idx < end; ++idx) {\n\t\t\tencoding += BYTE_TO_HEX[bytes[idx]];\n\t\t}\n\t\treturn encoding;\n\t}\n}\n\nmodule.exports = new HexCoder;\n"
  },
  {
    "path": "src/coder/uuid.js",
    "content": "'use strict';\n\nconst { BaseCoder } = require('./base');\n\nconst ALPHABET = '0123456789ABCDEF';\n\nconst BYTE_TO_HEX = Array\n\t.from({ length: ALPHABET.length * ALPHABET.length })\n\t.map((_, key) => (\n\t\t''\n\t\t+ ALPHABET.charAt(key / ALPHABET.length)\n\t\t+ ALPHABET.charAt(key % ALPHABET.length)\n\t));\n\nconst HEX_TO_BYTE = Array.from(ALPHABET).reduce(\n\t(mapping, hex, idx) => Object.assign(mapping, {\n\t\t[hex.toUpperCase()]: idx,\n\t\t[hex.toLowerCase()]: idx,\n\t}),\n\tObject.create(null)\n);\n\nclass UuidCoder extends BaseCoder {\n\tconstructor() {\n\t\tsuper({\n\t\t\tvalid_encoding_pattern: /^[0-9A-Fa-f]{4}(?:-?[0-9A-Fa-f]{4}){7}$/,\n\t\t});\n\t}\n\n\tdecodeTrusted(encoding) {\n\t\tlet bytes = new Uint8Array(16);\n\n\t\tfor (\n\t\t\tlet\n\t\t\t\tdst = 0,\n\t\t\t\thi_hex = true,\n\t\t\t\tsrc = 0,\n\t\t\t\tend = encoding.length;\n\t\t\tsrc < end;\n\t\t\t++src\n\t\t) {\n\t\t\tconst hex = encoding[src];\n\t\t\tif(hex !== '-') {\n\t\t\t\tif (hi_hex) {\n\t\t\t\t\tbytes[dst] = HEX_TO_BYTE[hex] << 4;\n\t\t\t\t} else {\n\t\t\t\t\tbytes[dst++] |= HEX_TO_BYTE[hex];\n\t\t\t\t}\n\t\t\t\thi_hex = ! hi_hex;\n\t\t\t}\n\t\t}\n\n\t\treturn bytes;\n\t}\n\n\tencodeTrusted(bytes) {\n\t\tlet idx = -1;\n\t\tconst encoding = (''\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ '-'\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ '-'\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ '-'\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ '-'\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t\t+ BYTE_TO_HEX[bytes[++idx]] + BYTE_TO_HEX[bytes[++idx]]\n\t\t);\n\t\treturn encoding;\n\t}\n}\n\nmodule.exports = new UuidCoder;\n\n"
  },
  {
    "path": "src/common/byte-array.js",
    "content": "const { randomBytes } = require('./random-bytes');\n\nconst MAX_BYTES = 16;\n\nclass ByteArray {\n\tcompare(lhs, rhs) {\n\t\tconst mismatch_idx =\n\t\t\tlhs.findIndex((byt, idx) => (byt !== rhs[idx]));\n\t\treturn ~mismatch_idx\n\t\t\t&& Math.sign(lhs[mismatch_idx] - rhs[mismatch_idx]);\n\t}\n\n\tgenerateOneFilled() {\n\t\treturn new Uint8Array(MAX_BYTES).fill(0xFF);\n\t}\n\n\tgenerateRandomFilled() {\n\t\treturn randomBytes(MAX_BYTES);\n\t}\n\n\tgenerateZeroFilled() {\n\t\treturn new Uint8Array(MAX_BYTES).fill(0);\n\t}\n}\n\nmodule.exports = new ByteArray;\n"
  },
  {
    "path": "src/common/epoch-converter.js",
    "content": "const { InvalidEpoch } = require('./exception');\n\nconst MIN_MS = 0;\nconst MAX_MS = Math.pow(2, 48);\n\nclass EpochConverter {\n\tfromEpoch(origin_ms, epoch_ms) {\n\t\treturn new Date(epoch_ms + origin_ms);\n\t}\n\n\ttoEpoch(origin_ms, time = null) {\n\t\tconst coerced_ms =\n\t\t\ttime === null ? Date.now() :\n\t\t\tNumber.isInteger(time) ? time :\n\t\t\ttime instanceof Date ? time.getTime() :\n\t\t\t\t(() => {\n\t\t\t\t\tthrow new InvalidEpoch(`Failed to coerce time [${time}] to epoch`);\n\t\t\t\t})();\n\n\t\tconst epoch_ms = coerced_ms - origin_ms;\n\n\t\tif (epoch_ms < MIN_MS || epoch_ms >= MAX_MS) {\n\t\t\tconst min_iso = new Date(MIN_MS + origin_ms).toISOString();\n\t\t\tconst max_iso = new Date(MAX_MS - 1 + origin_ms).toISOString();\n\t\t\tthrow new InvalidEpoch(`Epoch must be between ${min_iso} and ${max_iso}`);\n\t\t}\n\n\t\treturn epoch_ms;\n\t}\n}\n\nmodule.exports = new EpochConverter;\n"
  },
  {
    "path": "src/common/exception.js",
    "content": "class Id128Error extends Error {\n\tget name() { return this.constructor.name }\n}\n\nclass ClockSequenceOverflow extends Id128Error {}\nclass InvalidBytes extends Id128Error {}\nclass InvalidEncoding extends Id128Error {}\nclass InvalidEpoch extends Id128Error {}\nclass UnsupportedVersion extends Id128Error {}\n\nmodule.exports = {\n\tId128Error,\n\tClockSequenceOverflow,\n\tInvalidBytes,\n\tInvalidEncoding,\n\tInvalidEpoch,\n\tUnsupportedVersion,\n};\n"
  },
  {
    "path": "src/common/fake-machine.js",
    "content": "const { randomBytes } = require('./random-bytes');\n\nconst _mac_address = Symbol('mac-address');\n\nclass FakeMachine {\n\tconstructor() {\n\t\tthis.reset();\n\t}\n\n\tget mac_address() {\n\t\tlet mac_address = this[_mac_address];\n\n\t\tif (! mac_address) {\n\t\t\tmac_address = this[_mac_address] = randomBytes(6);\n\t\t\tmac_address[0] |= 0b00000001;\n\t\t}\n\n\t\treturn mac_address;\n\t}\n\n\treset() {\n\t\tthis[_mac_address] = null;\n\t}\n}\n\nmodule.exports = new FakeMachine;\n"
  },
  {
    "path": "src/common/machine.js",
    "content": "const Os = require('os');\nconst { randomBytes } = require('./random-bytes');\n\nconst _mac_address = Symbol('mac-address');\n\nclass Machine {\n\tconstructor() {\n\t\tthis.reset();\n\t}\n\n\tget mac_address() {\n\t\tlet mac_address = this[_mac_address];\n\n\t\tif (! mac_address) {\n\t\t\tconst { mac } = Object.values(Os.networkInterfaces())\n\t\t\t\t.reduce((memo, arr) => memo.concat(arr), [])\n\t\t\t\t.find((iface) => ! iface.internal && iface.mac)\n\t\t\t\t|| {};\n\n\t\t\tmac_address = this[_mac_address] = mac\n\t\t\t\t? Uint8Array.from(mac.split(':'), (hex) => Number.parseInt(hex, 16))\n\t\t\t\t: randomBytes(6);\n\n\t\t\tif (! mac) {\n\t\t\t\tmac_address[0] |= 0b00000001;\n\t\t\t}\n\t\t}\n\n\t\treturn mac_address;\n\t}\n\n\treset() {\n\t\tthis[_mac_address] = null;\n\t}\n}\n\nmodule.exports = new Machine;\n"
  },
  {
    "path": "src/common/random-bytes-browser.js",
    "content": "const Crypto = self.crypto;\n\nfunction randomBytes(size) {\n\tconst bytes = new Uint8Array(size);\n\tCrypto.getRandomValues(bytes);\n\treturn bytes;\n};\n\nmodule.exports = { randomBytes };\n"
  },
  {
    "path": "src/common/random-bytes.js",
    "content": "const Crypto = require('crypto');\n\nconst BUFFER_SIZE = 4096 /* typical page size */ - 96 /* Empty buffer overhead */;\n\nconst buffer = new Uint8Array(BUFFER_SIZE)\nlet offset = BUFFER_SIZE;\n\nfunction randomBytes(size) {\n\tif (offset + size >= BUFFER_SIZE) {\n\t\toffset = 0;\n\t\tCrypto.randomFillSync(buffer)\n\t}\n\n\treturn buffer.slice(offset, offset += size);\n}\n\nmodule.exports = { randomBytes };\n"
  },
  {
    "path": "src/factory/id.js",
    "content": "'use strict';\n\nconst _id = Symbol('id');\nconst _canonical_coder = Symbol('canonical_coder');\nconst _raw_coder = Symbol('raw_coder');\n\nclass IdFactory {\n\tconstructor({\n\t\tid,\n\t\tcanonical_coder,\n\t\traw_coder,\n\t} = {}) {\n\t\tthis[_id] = class extends id {\n\t\t\tstatic get name() { return id.name; }\n\t\t\tstatic get [Symbol.species]() { return id; }\n\t\t\tget [Symbol.toStringTag]() { return `${id.name} ${this.toRaw()}`; }\n\t\t\ttoCanonical() { return canonical_coder.encodeTrusted(this.bytes); }\n\t\t\ttoRaw() { return raw_coder.encodeTrusted(this.bytes); }\n\t\t};\n\t\tthis[_canonical_coder] = canonical_coder;\n\t\tthis[_raw_coder] = raw_coder;\n\t}\n\n\t// Properties\n\n\tget name() { return this[_id].name; }\n\tget type() { return this[_id][Symbol.species]; }\n\n\t// Generators\n\n\tconstruct(bytes) {\n\t\treturn new this[_id](bytes);\n\t}\n\n\tgenerate() {\n\t\treturn this[_id].generate(...arguments);\n\t}\n\n\tMIN() {\n\t\treturn this[_id].MIN(...arguments);\n\t}\n\n\tMAX() {\n\t\treturn this[_id].MAX(...arguments);\n\t}\n\n\t// Coders\n\n\tfromCanonical(canonical) {\n\t\treturn this.construct(this[_canonical_coder].decode(canonical));\n\t}\n\n\tfromCanonicalTrusted(canonical) {\n\t\treturn this.construct(this[_canonical_coder].decodeTrusted(canonical));\n\t}\n\n\tfromRaw(raw) {\n\t\treturn this.construct(this[_raw_coder].decode(raw));\n\t}\n\n\tfromRawTrusted(raw) {\n\t\treturn this.construct(this[_raw_coder].decodeTrusted(raw));\n\t}\n\n\ttoCanonical(id) {\n\t\treturn this[_canonical_coder].encode(id.bytes);\n\t}\n\n\ttoRaw(id) {\n\t\treturn this[_raw_coder].encode(id.bytes);\n\t}\n\n\t// Comparators\n\n\tcompare(lhs, rhs) {\n\t\tconsole.warn(\"Deprecated: use generic idCompare instead.\")\n\t\treturn lhs.compare(rhs);\n\t}\n\n\tequal(lhs, rhs) {\n\t\tconsole.warn(\"Deprecated: use generic idEqual instead.\")\n\t\treturn lhs.equal(rhs);\n\t}\n\n\t// Verifiers\n\n\tisCanonical(canonical) {\n\t\treturn this[_canonical_coder].isValidEncoding(canonical);\n\t}\n\n\tisRaw(raw) {\n\t\treturn this[_raw_coder].isValidEncoding(raw);\n\t}\n}\n\nmodule.exports = { IdFactory };\n"
  },
  {
    "path": "src/factory/versioned-id.js",
    "content": "'use strict';\n\nconst { IdFactory } = require('./id');\nconst { UnsupportedVersion } = require('../common/exception');\n\nconst _id_by_version = Symbol('id_by_version');\n\nfunction detect(factory, { version } = {}) {\n\treturn factory[_id_by_version][version]\n\t\t|| (() => { throw new UnsupportedVersion(\n\t\t\t`No support for version [${version}]`\n\t\t) })();\n}\n\nclass VersionedIdFactory extends IdFactory {\n\tconstructor({\n\t\tabstract_id,\n\t\tversioned_ids,\n\t\tcanonical_coder,\n\t\traw_coder,\n\t}) {\n\t\tsuper({\n\t\t\tid: abstract_id,\n\t\t\tcanonical_coder,\n\t\t\traw_coder,\n\t\t});\n\n\t\tthis[_id_by_version] = versioned_ids.reduce(\n\t\t\t(mapping, id) => Object.assign(mapping, {\n\t\t\t\t[id.MIN().version]: new IdFactory({\n\t\t\t\t\tid,\n\t\t\t\t\tcanonical_coder,\n\t\t\t\t\traw_coder,\n\t\t\t\t})\n\t\t\t}),\n\t\t\tObject.create(null),\n\t\t);\n\t}\n\n\tget versioned_ids() {\n\t\treturn Object.values(this[_id_by_version]);\n\t}\n\n\t// Generators\n\n\tconstruct(bytes) {\n\t\tconst id = super.construct(bytes);\n\t\tconst version = id.version;\n\n\t\ttry {\n\t\t\treturn detect(this, { version }).construct(bytes);\n\t\t}\n\t\tcatch (error) {\n\t\t\tif (error instanceof UnsupportedVersion) { return id }\n\t\t\telse { throw error }\n\t\t}\n\t}\n\n\tgenerate() {\n\t\treturn detect(this, ...arguments).generate(...arguments);\n\t}\n\n\tMIN() {\n\t\treturn detect(this, ...arguments).MIN();\n\t}\n\n\tMAX() {\n\t\treturn detect(this, ...arguments).MAX();\n\t}\n}\n\nmodule.exports = { VersionedIdFactory };\n"
  },
  {
    "path": "src/id/base.js",
    "content": "'use strict';\n\nconst ByteArray = require('../common/byte-array');\n\nconst _bytes = Symbol('bytes');\n\nclass BaseId {\n\t//Constructors\n\n\tconstructor(bytes) {\n\t\tthis[_bytes] = bytes;\n\t}\n\n\tclone() {\n\t\treturn new this.constructor(this.bytes.slice());\n\t}\n\n\t// Accessors\n\n\tget bytes() {\n\t\treturn this[_bytes];\n\t}\n\n\tget [Symbol.toStringTag]() {\n\t\treturn this.constructor.name;\n\t}\n\n\t// Comparators\n\n\tcompare(rhs) {\n\t\treturn ByteArray.compare(this.bytes, rhs.bytes);\n\t}\n\n\tequal(rhs) {\n\t\treturn this.compare(rhs) === 0;\n\t}\n}\n\nmodule.exports = { BaseId };\n"
  },
  {
    "path": "src/id/ulid-monotonic.js",
    "content": "const { Ulid, setTime } = require('./ulid');\nconst ByteArray = require('../common/byte-array');\nconst EpochConverter = require('../common/epoch-converter');\nconst { ClockSequenceOverflow } = require('../common/exception');\n\nconst TIME_OFFSET = 0;\nconst CLOCK_SEQUENCE_OFFSET = 6;\nconst RANDOM_OFFSET = 8;\n\nconst EPOCH_ORIGIN_MS = 0;\n\nlet _previous_id;\nlet _previous_time;\n\nfunction incrementClockSequence(bytes) {\n\tfor (\n\t\tlet\n\t\t\tidx = RANDOM_OFFSET - 1,\n\t\t\tend = CLOCK_SEQUENCE_OFFSET - 1;\n\t\tidx > end;\n\t\t--idx\n\t) {\n\t\tif (bytes[idx] === 0xFF) {\n\t\t\tbytes[idx] = 0;\n\t\t} else {\n\t\t\t++bytes[idx];\n\t\t\treturn;\n\t\t}\n\t}\n\n\tthrow new ClockSequenceOverflow('Exhausted clock sequence');\n};\n\nfunction reserveClockSequence(bytes) {\n\tbytes[CLOCK_SEQUENCE_OFFSET] &= 0b01111111;\n};\n\nfunction restoreClockSequence(bytes) {\n\tfor (let idx = TIME_OFFSET; idx < RANDOM_OFFSET; ++idx) {\n\t\tbytes[idx] = _previous_id.bytes[idx];\n\t}\n};\n\nclass UlidMonotonic extends Ulid {\n\tstatic reset() {\n\t\t_previous_time = -1;\n\t\t_previous_id = this.MIN();\n\t}\n\n\t//Constructors\n\n\tstatic generate({ time } = {}) {\n\t\ttime = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);\n\t\tlet bytes = ByteArray.generateRandomFilled();\n\n\t\tif (time <= _previous_time) {\n\t\t\trestoreClockSequence(bytes);\n\t\t\tincrementClockSequence(bytes);\n\t\t} else {\n\t\t\tsetTime(time, bytes)\n\t\t\treserveClockSequence(bytes);\n\t\t\t_previous_time = time;\n\t\t}\n\n\t\treturn (_previous_id = new this(bytes));\n\t}\n}\n\nUlidMonotonic.reset();\n\nmodule.exports = { UlidMonotonic };\n"
  },
  {
    "path": "src/id/ulid.js",
    "content": "const ByteArray = require('../common/byte-array');\nconst EpochConverter = require('../common/epoch-converter');\nconst { BaseId } = require('./base');\n\nconst TIME_OFFSET = 0;\n\nconst EPOCH_ORIGIN_MS = 0;\nconst UINT32_RADIX = Math.pow(2, 32);\nconst UINT8_MAX = 0b11111111;\n\nfunction setTime(time, bytes) {\n\tconst time_low = time % UINT32_RADIX;\n\tconst time_high = (time - time_low) / UINT32_RADIX;\n\n\tlet idx = TIME_OFFSET - 1;\n\tbytes[++idx] = (time_high >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 0) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 24) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 16) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 0) & UINT8_MAX;\n}\n\nclass Ulid extends BaseId {\n\n\t//Constructors\n\n\tstatic generate({ time } = {}) {\n\t\ttime = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);\n\n\t\tlet bytes = ByteArray.generateRandomFilled();\n\n\t\tsetTime(time, bytes);\n\n\t\treturn new this(bytes);\n\t}\n\n\tstatic MIN() {\n\t\treturn new this(ByteArray.generateZeroFilled());\n\t}\n\n\tstatic MAX() {\n\t\treturn new this(ByteArray.generateOneFilled());\n\t}\n\n\t// Accessors\n\n\tget time() {\n\t\tlet idx = TIME_OFFSET - 1;\n\t\tconst time_high = 0\n\t\t\t| (this.bytes[++idx] << 8)\n\t\t\t| (this.bytes[++idx] << 0);\n\t\tconst time_low = 0\n\t\t\t| (this.bytes[++idx] << 24)\n\t\t\t| (this.bytes[++idx] << 16)\n\t\t\t| (this.bytes[++idx] << 8)\n\t\t\t| (this.bytes[++idx] << 0);\n\t\tconst epoch_ms = (time_high * UINT32_RADIX) + (time_low >>> 0);\n\n\t\treturn EpochConverter.fromEpoch(EPOCH_ORIGIN_MS, epoch_ms);\n\t};\n}\n\nmodule.exports = { Ulid, setTime };\n"
  },
  {
    "path": "src/id/uuid-1.js",
    "content": "'use strict';\n\nconst ByteArray = require('../common/byte-array');\nconst EpochConverter = require('../common/epoch-converter');\nconst Machine = require('../common/machine');\nconst {\n\tUuid,\n\tsetVariant,\n\tsetVersion,\n} = require('./uuid');\n\nconst TIME_OFFSET = 0;\nconst HIRES_TIME_OFFSET = 2;\nconst CLOCK_SEQUENCE_OFFSET = 8;\nconst NODE_OFFSET = 10;\n\nconst CLOCK_SEQUENCE_RADIX = Math.pow(2, 14);\nconst EPOCH_ORIGIN_MS = Date.parse('1582-10-15Z');\nconst HIRES_TIME_RADIX = Math.pow(2, 12);\nconst TIME_LOW_MS_RADIX = Math.pow(2, 20);\nconst UINT8_MAX = 0b11111111;\n\nlet _clock_sequence;\nlet _hires_time;\nlet _previous_time;\n\nfunction incrementClockSequence() {\n\t_clock_sequence = (_clock_sequence + 1) % CLOCK_SEQUENCE_RADIX;\n}\n\nfunction setClockSequence(time, bytes) {\n\tif (_clock_sequence === null) {\n\t\tconst random_bytes = ByteArray.generateRandomFilled();\n\t\t_clock_sequence = (\n\t\t\t0\n\t\t\t| random_bytes[CLOCK_SEQUENCE_OFFSET + 0] << 8\n\t\t\t| random_bytes[CLOCK_SEQUENCE_OFFSET + 1] << 0\n\t\t) % CLOCK_SEQUENCE_RADIX;\n\t}\n\telse if (time < _previous_time) {\n\t\tincrementClockSequence();\n\t}\n\n\tlet idx = CLOCK_SEQUENCE_OFFSET - 1;\n\tbytes[++idx] = (_clock_sequence >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (_clock_sequence >>> 0) & UINT8_MAX;\n}\n\nfunction setNode(node, bytes) {\n\tfor (let idx = 0; idx < 6; ++idx) {\n\t\tbytes[NODE_OFFSET + idx] = node[idx];\n\t}\n}\n\nfunction setTime(time, bytes) {\n\t_hires_time = time > _previous_time ? 0 : _hires_time + 1;\n\tif (_hires_time === HIRES_TIME_RADIX) {\n\t\t_hires_time = 0;\n\t\tincrementClockSequence();\n\t}\n\n\tconst time_low_ms = time % TIME_LOW_MS_RADIX;\n\tconst time_low = time_low_ms * HIRES_TIME_RADIX + _hires_time;\n\tconst time_high = (time - time_low_ms) / TIME_LOW_MS_RADIX;\n\n\tlet idx = TIME_OFFSET - 1;\n\tbytes[++idx] = (time_low >>> 24) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 16) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 0) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 0) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 24) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 16) & UINT8_MAX;\n}\n\nclass Uuid1 extends Uuid {\n\tstatic get VARIANT() { return 1 }\n\tstatic get VERSION() { return 1 }\n\n\tstatic reset() {\n\t\t_clock_sequence = null;\n\t\t_hires_time = -1;\n\t\t_previous_time = -1;\n\t}\n\n\t//Constructors\n\n\tstatic generate({ node, time } = {}) {\n\t\ttime = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);\n\n\t\tlet bytes = ByteArray.generateZeroFilled();\n\n\t\tsetTime(time, bytes);\n\t\tsetClockSequence(time, bytes);\n\t\tsetNode(node || Machine.mac_address, bytes);\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\tif (time > _previous_time) {\n\t\t\t_previous_time = time;\n\t\t}\n\n\t\treturn new this(bytes);\n\t}\n\n\t// Accessors\n\n\tget clock_sequence() {\n\t\treturn (\n\t\t\t0\n\t\t\t| this.bytes[CLOCK_SEQUENCE_OFFSET] << 8\n\t\t\t| this.bytes[CLOCK_SEQUENCE_OFFSET + 1]\n\t\t) & (CLOCK_SEQUENCE_RADIX - 1);\n\t}\n\n\tget hires_time() {\n\t\treturn (\n\t\t\t0\n\t\t\t| this.bytes[HIRES_TIME_OFFSET] << 8\n\t\t\t| this.bytes[HIRES_TIME_OFFSET + 1]\n\t\t) & (HIRES_TIME_RADIX - 1);\n\t}\n\n\tget node() {\n\t\treturn this.bytes.slice(NODE_OFFSET);\n\t}\n\n\tget time() {\n\t\tlet idx = TIME_OFFSET - 1;\n\t\tconst time_low_ms = 0\n\t\t\t| (this.bytes[++idx] << 12)\n\t\t\t| (this.bytes[++idx] << 4)\n\t\t\t| (this.bytes[++idx] >>> 4);\n\t\t++idx; // Skip hi-res bits\n\t\tconst time_high = 0\n\t\t\t| (this.bytes[++idx] << 8)\n\t\t\t| (this.bytes[++idx] << 0)\n\t\t\t| ((this.bytes[++idx] & 0x0F) << 24)\n\t\t\t| (this.bytes[++idx] << 16);\n\t\tconst epoch_ms = time_high * TIME_LOW_MS_RADIX + time_low_ms;\n\n\t\treturn EpochConverter.fromEpoch(EPOCH_ORIGIN_MS, epoch_ms);\n\t};\n}\n\nUuid1.reset();\n\nmodule.exports = { Uuid1 };\n"
  },
  {
    "path": "src/id/uuid-4.js",
    "content": "'use strict';\n\nconst ByteArray = require('../common/byte-array');\nconst {\n\tUuid,\n\tsetVariant,\n\tsetVersion,\n} = require('./uuid');\n\nclass Uuid4 extends Uuid {\n\tstatic get VARIANT() { return 1 }\n\tstatic get VERSION() { return 4 }\n\n\tstatic generate() {\n\t\tlet bytes = ByteArray.generateRandomFilled();\n\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\treturn new this(bytes);\n\t}\n}\n\nmodule.exports = { Uuid4 };\n"
  },
  {
    "path": "src/id/uuid-6.js",
    "content": "'use strict';\n\nconst ByteArray = require('../common/byte-array');\nconst EpochConverter = require('../common/epoch-converter');\nconst Machine = require('../common/machine');\nconst {\n\tUuid,\n\tsetVariant,\n\tsetVersion,\n} = require('./uuid');\n\nconst TIME_OFFSET = 0;\nconst HIRES_TIME_OFFSET = 6;\nconst CLOCK_SEQUENCE_OFFSET = 8;\nconst NODE_OFFSET = 10;\n\nconst CLOCK_SEQUENCE_RADIX = Math.pow(2, 14);\nconst EPOCH_ORIGIN_MS = Date.parse('1582-10-15Z');\nconst HIRES_TIME_RADIX = Math.pow(2, 12);\nconst UINT32_RADIX = Math.pow(2, 32);\nconst UINT8_MAX = 0b11111111;\n\nlet _clock_sequence;\nlet _hires_time;\nlet _previous_time;\n\nfunction incrementClockSequence() {\n\t_clock_sequence = (_clock_sequence + 1) % CLOCK_SEQUENCE_RADIX;\n}\n\nfunction setClockSequence(time, bytes) {\n\tif (_clock_sequence === null) {\n\t\tconst random_bytes = ByteArray.generateRandomFilled();\n\t\t_clock_sequence = (\n\t\t\t0\n\t\t\t| random_bytes[CLOCK_SEQUENCE_OFFSET + 0] << 8\n\t\t\t| random_bytes[CLOCK_SEQUENCE_OFFSET + 1] << 0\n\t\t) % CLOCK_SEQUENCE_RADIX;\n\t}\n\telse if (time < _previous_time) {\n\t\tincrementClockSequence();\n\t}\n\n\tlet idx = CLOCK_SEQUENCE_OFFSET - 1;\n\tbytes[++idx] = (_clock_sequence >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (_clock_sequence >>> 0) & UINT8_MAX;\n}\n\nfunction setNode(node, bytes) {\n\tfor (let idx = 0; idx < 6; ++idx) {\n\t\tbytes[NODE_OFFSET + idx] = node[idx];\n\t}\n}\n\nfunction setTime(time, bytes) {\n\t_hires_time = time > _previous_time ? 0 : _hires_time + 1;\n\tif (_hires_time === HIRES_TIME_RADIX) {\n\t\t_hires_time = 0;\n\t\tincrementClockSequence();\n\t}\n\n\tconst time_low = time % UINT32_RADIX;\n\tconst time_high = (time - time_low) / UINT32_RADIX;\n\n\tlet idx = TIME_OFFSET - 1;\n\tbytes[++idx] = (time_high >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_high >>> 0) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 24) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 16) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (time_low >>> 0) & UINT8_MAX;\n\tbytes[++idx] = (_hires_time >>> 8) & UINT8_MAX;\n\tbytes[++idx] = (_hires_time >>> 0) & UINT8_MAX;\n}\n\nclass Uuid6 extends Uuid {\n\tstatic get VARIANT() { return 1 }\n\tstatic get VERSION() { return 6 }\n\n\tstatic reset() {\n\t\t_clock_sequence = null;\n\t\t_hires_time = -1;\n\t\t_previous_time = -1;\n\t}\n\n\t//Constructors\n\n\tstatic generate({ node, time } = {}) {\n\t\ttime = EpochConverter.toEpoch(EPOCH_ORIGIN_MS, time);\n\n\t\tlet bytes = ByteArray.generateZeroFilled();\n\n\t\tsetTime(time, bytes);\n\t\tsetClockSequence(time, bytes);\n\t\tsetNode(node || Machine.mac_address, bytes);\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\tif (time > _previous_time) {\n\t\t\t_previous_time = time;\n\t\t}\n\n\t\treturn new this(bytes);\n\t}\n\n\t// Accessors\n\n\tget clock_sequence() {\n\t\treturn (\n\t\t\t0\n\t\t\t| this.bytes[CLOCK_SEQUENCE_OFFSET] << 8\n\t\t\t| this.bytes[CLOCK_SEQUENCE_OFFSET + 1]\n\t\t) & (CLOCK_SEQUENCE_RADIX - 1);\n\t}\n\n\tget hires_time() {\n\t\treturn (\n\t\t\t0\n\t\t\t| this.bytes[HIRES_TIME_OFFSET] << 8\n\t\t\t| this.bytes[HIRES_TIME_OFFSET + 1]\n\t\t) & (HIRES_TIME_RADIX - 1);\n\t}\n\n\tget node() {\n\t\treturn this.bytes.slice(NODE_OFFSET);\n\t}\n\n\tget time() {\n\t\tlet idx = TIME_OFFSET - 1;\n\t\tconst time_high = 0\n\t\t\t| (this.bytes[++idx] << 8)\n\t\t\t| (this.bytes[++idx] << 0);\n\t\tconst time_low = 0\n\t\t\t| (this.bytes[++idx] << 24)\n\t\t\t| (this.bytes[++idx] << 16)\n\t\t\t| (this.bytes[++idx] << 8)\n\t\t\t| (this.bytes[++idx] << 0);\n\t\tconst epoch_ms = (time_high * UINT32_RADIX) + (time_low >>> 0);\n\n\t\treturn EpochConverter.fromEpoch(EPOCH_ORIGIN_MS, epoch_ms);\n\t};\n}\n\nUuid6.reset();\n\nmodule.exports = { Uuid6 };\n"
  },
  {
    "path": "src/id/uuid-nil.js",
    "content": "'use strict';\n\nconst ByteArray = require('../common/byte-array');\nconst {\n\tUuid,\n\tsetVariant,\n\tsetVersion,\n} = require('./uuid');\n\nclass UuidNil extends Uuid {\n\tstatic get VARIANT() { return 0 }\n\tstatic get VERSION() { return 0 }\n\n\tstatic generate() {\n\t\tlet bytes = ByteArray.generateZeroFilled();\n\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\treturn new this(bytes);\n\t}\n\n\tstatic MAX() {\n\t\tlet bytes = ByteArray.generateZeroFilled();\n\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\treturn new this(bytes);\n\t}\n}\n\nmodule.exports = { UuidNil };\n"
  },
  {
    "path": "src/id/uuid.js",
    "content": "'use strict';\n\nconst { BaseId } = require('./base');\nconst ByteArray = require('../common/byte-array');\n\nconst VARIANT_BYTE = 8;\nconst VERSION_BYTE = 6;\n\nfunction setVariant(variant, bytes) {\n\tbytes[VARIANT_BYTE] &= 0b11111111 >>> (variant + 1);\n\tbytes[VARIANT_BYTE] |= ((0b111 << (3 - variant)) & 0b111) << 5;\n};\n\nfunction setVersion(version, bytes) {\n\tbytes[VERSION_BYTE] &= 0b00001111;\n\tbytes[VERSION_BYTE] |= version << 4;\n};\n\nclass Uuid extends BaseId {\n\tstatic MIN() {\n\t\tlet bytes = ByteArray.generateZeroFilled();\n\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\treturn new this(bytes);\n\t}\n\n\tstatic MAX() {\n\t\tlet bytes = ByteArray.generateOneFilled();\n\n\t\tsetVariant(this.VARIANT, bytes);\n\t\tsetVersion(this.VERSION, bytes);\n\n\t\treturn new this(bytes);\n\t}\n\n\tget variant() {\n\t\tconst bits = this.bytes[VARIANT_BYTE] >>> 5;\n\n\t\treturn (\n\t\t\tbits === 0b111 ? 3 :\n\t\t\t(bits & 0b110) === 0b110 ? 2 :\n\t\t\t(bits & 0b100) === 0b100 ? 1 :\n\t\t\t\t0\n\t\t);\n\t}\n\n\tget version() {\n\t\treturn this.bytes[VERSION_BYTE] >>> 4;\n\t}\n}\n\nmodule.exports = {\n\tUuid,\n\tsetVersion,\n\tsetVariant,\n};\n"
  },
  {
    "path": "test/coder/crockford32.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tALPHABET,\n\tassertDecode,\n\tassertEncode,\n\tdescribeNamespace,\n\tmakeBytes,\n\tmakeString,\n} = require('./shared');\n\nconst { InvalidEncoding } = require('common/exception');\n\nconst described_namespace =  require('coder/crockford32');\n\nconst encoding_any = ''\n\t+ makeString(1, '01234567')\n\t+ makeString(25, ALPHABET.CROCKFORD32);\nconst encoding_max = '7' + makeString(25, 'Z');\nconst encoding_min = makeString(26, '0');\n\ndescribe(describeNamespace(described_namespace, encoding_any), function() {\n\tassertDecode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n\n\tdescribe('.decode', function() {\n\t\tconst subject = described_namespace.decode.bind(described_namespace);\n\n\t\tit('requires a 26-character Crockford32 string', function() {\n\t\t\t[\n\t\t\t\tsubject,\n\t\t\t\tsubject.bind(null, makeBytes(26)),\n\t\t\t\tsubject.bind(null, encoding_any.slice(0, -1)),\n\t\t\t\tsubject.bind(null, encoding_any + makeString(1, ALPHABET.CROCKFORD32)),\n\t\t\t\tsubject.bind(null, makeString(25, ALPHABET.ASCII) + '!'),\n\t\t\t].forEach(expectation => expect(subject).to.throw(InvalidEncoding));\n\n\t\t\texpect(subject.bind(null, encoding_any)).not.to.throw();\n\t\t});\n\t});\n\n\tdescribe('.decodeTrusted extended', function() {\n\t\tconst subject = described_namespace.decodeTrusted.bind(described_namespace);\n\n\t\tit('ignores case', function() {\n\t\t\tconst encoding = makeString(1, '01234567')\n\t\t\t\t+ makeString(25, ALPHABET.CROCKFORD32 + ALPHABET.CROCKFORD32.toLowerCase());\n\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toUpperCase()));\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toLowerCase()));\n\t\t});\n\n\t\tit('converts visually similar characters', function() {\n\t\t\tconst encoding = encoding_any.slice(0, -1);\n\t\t\tconst conversions = [\n\t\t\t\t['i', '1'],\n\t\t\t\t['I', '1'],\n\t\t\t\t['l', '1'],\n\t\t\t\t['L', '1'],\n\t\t\t\t['o', '0'],\n\t\t\t\t['O', '0'],\n\t\t\t\t['u', 'V'],\n\t\t\t\t['U', 'V'],\n\t\t\t];\n\n\t\t\tconversions.forEach(([character, replacement]) => {\n\t\t\t\texpect(subject(encoding + character), `Failed to convert ${character}`)\n\t\t\t\t\t.to.deep.equal(subject(encoding + replacement));\n\t\t\t});\n\t\t});\n\t});\n\n\tassertEncode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n});\n\n"
  },
  {
    "path": "test/coder/hex.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tALPHABET,\n\tassertDecode,\n\tassertEncode,\n\tdescribeNamespace,\n\tmakeBytes,\n\tmakeString,\n} = require('./shared');\n\nconst { InvalidEncoding } = require('common/exception');\n\nconst described_namespace = require('coder/hex');\n\nconst encoding_any = makeString(32, ALPHABET.HEX);\nconst encoding_max = makeString(32, 'F');\nconst encoding_min = makeString(32, '0');\n\ndescribe(describeNamespace(described_namespace, encoding_any), function() {\n\tassertDecode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n\n\tdescribe('.decode', function() {\n\t\tconst subject = described_namespace.decode.bind(described_namespace);\n\n\t\tit('requires a 32-character hex string', function() {\n\t\t\t[\n\t\t\t\tsubject,\n\t\t\t\tsubject.bind(null, makeBytes(32)),\n\t\t\t\tsubject.bind(null, encoding_any.slice(0, -1)),\n\t\t\t\tsubject.bind(null, encoding_any + makeString(1, ALPHABET.HEX)),\n\t\t\t\tsubject.bind(null, makeString(31, ALPHABET.ASCII) + '\\0'),\n\t\t\t].forEach(expectation => expect(subject).to.throw(InvalidEncoding));\n\n\t\t\texpect(subject.bind(null, encoding_any)).not.to.throw();\n\t\t});\n\t});\n\n\tdescribe('.decodeTrusted extended', function() {\n\t\tconst subject = described_namespace.decodeTrusted.bind(described_namespace);\n\n\t\tit('ignores case', function() {\n\t\t\tconst encoding = makeString(32, ALPHABET.HEX + ALPHABET.HEX.toLowerCase());\n\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toUpperCase()));\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toLowerCase()));\n\t\t});\n\t});\n\n\tassertEncode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n});\n"
  },
  {
    "path": "test/coder/shared.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst ByteArray = require('common/byte-array');\nconst {\n\tInvalidBytes,\n\tInvalidEncoding,\n} = require('common/exception');\n\n// Constants\n\nconst BYTES = Object.freeze({\n\tANY: ByteArray.generateRandomFilled(),\n\tMAX: ByteArray.generateOneFilled(),\n\tMIN: ByteArray.generateZeroFilled(),\n});\n\nconst ALPHABET = Object.freeze({\n\tASCII: Array.from({ length: 128 }, (v, k) => String.fromCharCode(k)).join(''),\n\tCROCKFORD32: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',\n\tHEX: '0123456789ABCDEF',\n});\n\n//Helpers\n\nfunction describeNamespace(described_namespace, encoding_any) {\n\treturn described_namespace.constructor.name\n\t\t+ ` (with random encoding ${encoding_any})`;\n}\n\nfunction makeBytes(length) {\n\treturn Uint8Array.from({length});\n}\n\nfunction makeString(length, alphabet) {\n\tconst generator = () => randomChar(alphabet);\n\treturn Array.from({length}, generator).join('');\n}\n\nfunction randomChar(alphabet) {\n\tconst random_idx = Math.floor(alphabet.length * Math.random());\n\treturn alphabet.charAt(random_idx);\n}\n\n//Assertions\n\nfunction assertDecode({\n\tdescribed_namespace,\n\tencoding_any,\n\tencoding_max,\n\tencoding_min,\n} = {}) {\n\tdescribe('.decodeTrusted', function() {\n\t\tconst subject = described_namespace.decodeTrusted.bind(described_namespace);\n\n\t\tit(`decodes ${encoding_min} to all 0-bits`, function() {\n\t\t\texpect(subject(encoding_min)).to.deep.equal(BYTES.MIN);\n\t\t});\n\n\t\tit(`decodes ${encoding_max} to all 1-bits`, function() {\n\t\t\texpect(subject(encoding_max)).to.deep.equal(BYTES.MAX);\n\t\t});\n\n\t\tit('inverts encode', function() {\n\t\t\texpect(subject(described_namespace.encode(BYTES.ANY)))\n\t\t\t\t.to.deep.equal(BYTES.ANY);\n\t\t});\n\t});\n}\n\nfunction assertEncode({\n\tdescribed_namespace,\n\tencoding_any,\n\tencoding_max,\n\tencoding_min,\n} = {}) {\n\tdescribe('.encode', function() {\n\t\tconst subject = described_namespace.encode.bind(described_namespace);\n\n\t\tit('requires a 16-byte Uint8Array', function() {\n\t\t\t[\n\t\t\t\tsubject,\n\t\t\t\tsubject.bind(null, makeString(16, '\\0')),\n\t\t\t\tsubject.bind(null, makeBytes(15)),\n\t\t\t\tsubject.bind(null, makeBytes(17)),\n\t\t\t].forEach((expectation) => expect(subject)\n\t\t\t\t.to.throw(InvalidBytes, 'Requires a 16-byte Uint8Array'));\n\n\t\t\texpect(subject.bind(null, BYTES.ANY)).not.to.throw();\n\t\t});\n\t});\n\n\tdescribe('.encodeTrusted', function() {\n\t\tconst subject = described_namespace.encodeTrusted.bind(described_namespace);\n\t\tit(`encodes all 0-bits to ${encoding_min}`, function() {\n\t\t\texpect(subject(BYTES.MIN)).to.equal(encoding_min);\n\t\t});\n\n\t\tit(`encodes all 1-bits to ${encoding_max}`, function() {\n\t\t\texpect(subject(BYTES.MAX)).to.equal(encoding_max);\n\t\t});\n\n\t\tit('inverts decode', function() {\n\t\t\texpect(subject(described_namespace.decode(encoding_any)))\n\t\t\t\t.to.equal(encoding_any);\n\t\t});\n\t});\n}\n\nmodule.exports = {\n\tALPHABET,\n\tassertDecode,\n\tassertEncode,\n\tdescribeNamespace,\n\tmakeBytes,\n\tmakeString,\n};\n"
  },
  {
    "path": "test/coder/uuid.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tALPHABET,\n\tassertDecode,\n\tassertEncode,\n\tdescribeNamespace,\n\tmakeBytes,\n\tmakeString,\n} = require('./shared');\n\nconst { InvalidEncoding } = require('common/exception');\n\nconst described_namespace =  require('coder/uuid');\n\nfunction makeUuid(alphabet) {\n\treturn [8, 4, 4, 4, 12].map(len => makeString(len, alphabet)).join('-');\n}\n\nconst encoding_any = makeUuid(ALPHABET.HEX);\nconst encoding_max = makeUuid('F');\nconst encoding_min = makeUuid('0');\n\ndescribe(describeNamespace(described_namespace, encoding_any), function() {\n\tassertDecode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n\n\tdescribe('.decode', function() {\n\t\tconst subject = described_namespace.decode.bind(described_namespace);\n\n\t\tit('requires a 32-character hex string (excluding hyphens)', function() {\n\t\t\t[\n\t\t\t\tsubject,\n\t\t\t\tsubject.bind(null, makeBytes(32)),\n\t\t\t\tsubject.bind(null, encoding_any.slice(0, -1)),\n\t\t\t\tsubject.bind(null, encoding_any + makeString(1, ALPHABET.HEX)),\n\t\t\t\tsubject.bind(null, makeString(31, ALPHABET.ASCII) + '\\0'),\n\t\t\t].forEach(expectation => expect(subject).to.throw(InvalidEncoding));\n\n\t\t\texpect(subject.bind(null, encoding_any)).not.to.throw();\n\t\t});\n\t});\n\n\tdescribe('.decodeTrusted extended', function() {\n\t\tconst subject = described_namespace.decodeTrusted.bind(described_namespace);\n\n\t\tit('accepts without hyphens', function() {\n\t\t\texpect(subject(encoding_any.replace(/-/g, '')))\n\t\t\t\t.to.deep.equal(subject(encoding_any));\n\t\t});\n\n\t\tit('accepts hyphens in even groups of 4', function() {\n\t\t\tconst encoding = encoding_any\n\t\t\t\t.replace(/-/g, '')\n\t\t\t\t.split(/(.{4})/)\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join('-');\n\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding_any));\n\t\t});\n\n\t\tit('ignores case', function() {\n\t\t\tconst encoding = makeUuid(ALPHABET.HEX + ALPHABET.HEX.toLowerCase());\n\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toUpperCase()));\n\t\t\texpect(subject(encoding)).to.deep.equal(subject(encoding.toLowerCase()));\n\t\t});\n\t});\n\n\tassertEncode({\n\t\tdescribed_namespace,\n\t\tencoding_any,\n\t\tencoding_max,\n\t\tencoding_min,\n\t});\n});\n"
  },
  {
    "path": "test/common/byte-array.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst described_namespace = require('common/byte-array');\n\nfunction assertByteArray(subject) {\n\tit('returns a Uint8Array', function() {\n\t\texpect(subject()).to.be.a('Uint8Array');\n\t});\n\n\tit('returns 16 bytes', function() {\n\t\texpect(subject()).to.have.lengthOf(16);\n\t});\n}\n\ndescribe(described_namespace.constructor.name, function() {\n\tdescribe('.compare', function() {\n\t\tconst subject = described_namespace.compare;\n\t\t[\n\t\t\t['lhs < rhs', [1], [9], -1],\n\t\t\t['lhs = rhs', [5], [5], 0],\n\t\t\t['lhs > rhs', [9], [1], 1],\n\t\t\t['non-leading lhs < rhs', [5, 9], [5, 3], 1],\n\t\t\t['non-leading lhs = rhs', [5, 7], [5, 7], 0],\n\t\t\t['non-leading lhs > rhs', [5, 3], [5, 9], -1],\n\t\t].forEach(([label, lhs, rhs, result]) => {\n\t\t\tit(`resolves ${label} to ${result}`, function() {\n\t\t\t\texpect(subject(lhs, rhs)).to.equal(result);\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('.generateOneFilled', function() {\n\t\tconst subject = described_namespace.generateOneFilled;\n\n\t\tassertByteArray(subject);\n\n\t\tit('has only one bits', function() {\n\t\t\texpect(subject().every((val) => val === 0xFF)).to.be.true;\n\t\t});\n\t});\n\n\tdescribe('.generateRandomFilled', function() {\n\t\tconst subject = described_namespace.generateRandomFilled;\n\n\t\tassertByteArray(subject);\n\n\t\tit('has mixed bits', function() {\n\t\t\t// NOTE: given the nature of random and the bit entropy,\n\t\t\t// we're guarding against extreme misfortune\n      this.retries(1);\n\n\t\t\tconst bytes = subject();\n\t\t\texpect(bytes.some((val) => val !== 0xFF)).to.be.true;\n\t\t\texpect(bytes.some((val) => val !== 0)).to.be.true;\n\t\t});\n\n\t\tit('almost always has different bits', function() {\n\t\t\t// NOTE: given the nature of random and the bit entropy,\n\t\t\t// we're guarding against extreme misfortune\n      this.retries(1);\n\n\t\t\texpect(subject()).not.to.deep.equal(subject());\n\t\t});\n\n\t\tit('every call allocates distinct memory', function() {\n\t\t\t// NOTE: given the nature of random and the bit entropy,\n\t\t\t// we're guarding against extreme misfortune\n      this.retries(1);\n\n\t\t\tconst byte_arrays = Array.from({ length: 1000 })\n\t\t\t\t.map(subject)\n\t\t\t\t.map(x => x.toString());\n\t\t\texpect(new Set(byte_arrays)).to.have.lengthOf(1000);\n\t\t});\n\t});\n\n\tdescribe('.generateZeroFilled', function() {\n\t\tconst subject = described_namespace.generateZeroFilled;\n\n\t\tassertByteArray(subject);\n\n\t\tit('has only zero bits', function() {\n\t\t\texpect(subject().every((val) => val === 0)).to.be.true;\n\t\t});\n\t});\n});\n"
  },
  {
    "path": "test/common/epoch-converter.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst { InvalidEpoch } = require('common/exception');\n\nconst described_namespace = require('common/epoch-converter');\n\ndescribe(described_namespace.constructor.name, function() {\n\tconst epoch_origin_ms = Date.parse('1955-11-05Z');\n\tconst min_time = 0 + epoch_origin_ms;\n\tconst max_time = Math.pow(2, 48) - 1 + epoch_origin_ms;\n\tconst now = Date.now();\n\n\tdescribe('.fromEpoch', function() {\n\t\tconst subject = (time) => described_namespace.fromEpoch(epoch_origin_ms, time);\n\n\t\tit('returns a Date', function() {\n\t\t\texpect(subject(0)).to.be.a('Date');\n\t\t});\n\n\t\tit('returns the time after adjusting for the origin', function() {\n\t\t\t[\n\t\t\t\t['min', 0, min_time],\n\t\t\t\t['origin', -epoch_origin_ms, 0],\n\t\t\t\t['now', now, now + epoch_origin_ms],\n\t\t\t\t['max', Math.pow(2, 48) - 1, max_time],\n\t\t\t].forEach(([label, epoch_ms, time]) => {\n\t\t\t\texpect(subject(epoch_ms).getTime(), label).to.equal(time);\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('.toEpoch', function() {\n\t\tconst subject = (time) => described_namespace.toEpoch(epoch_origin_ms, time);\n\n\t\tit('accepts a Date', function() {\n\t\t\t[\n\t\t\t\t['start of epoch time', new Date(min_time), 0],\n\t\t\t\t['origin of epoch time', new Date(0), -epoch_origin_ms],\n\t\t\t\t['current time', new Date(now + epoch_origin_ms), now],\n\t\t\t\t['end of epoch time', new Date(max_time), Math.pow(2, 48) - 1],\n\t\t\t].forEach(([label, value, epoch]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw();\n\t\t\t\texpect(subject(value), label).to.equal(epoch);\n\t\t\t});\n\t\t});\n\n\t\tit('accepts milliseconds', function() {\n\t\t\t[\n\t\t\t\t['start of epoch time', min_time, 0],\n\t\t\t\t['origin of epoch time', 0, -epoch_origin_ms],\n\t\t\t\t['current time', now + epoch_origin_ms, now],\n\t\t\t\t['end of epoch time', max_time, Math.pow(2, 48) - 1],\n\t\t\t].forEach(([label, value, epoch]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw();\n\t\t\t\texpect(subject(value), label).to.equal(epoch);\n\t\t\t});\n\t\t});\n\n\t\tit('defaults to now for null and undefined', function() {\n\t\t\t[\n\t\t\t\t['null', null],\n\t\t\t\t['undefined', void(null)],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\tconst now = Date.now() - epoch_origin_ms;\n\n\t\t\t\texpect(subject(value), label).to.be.within(now, now + 1);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects other falsey values', function() {\n\t\t\t[\n\t\t\t\t['false', false],\n\t\t\t\t['empty string', ''],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects other Date-like values', function() {\n\t\t\t[\n\t\t\t\t['date string', '2018-01-10'],\n\t\t\t\t['duck type', { getTime: (() => {}) }],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects pre/post-epoch values', function() {\n\t\t\t[\n\t\t\t\t['date before epoch time', new Date(min_time - 1)],\n\t\t\t\t['ms before epoch time', min_time - 1],\n\t\t\t\t['date after epoch time', new Date(max_time + 1)],\n\t\t\t\t['ms after epoch time', max_time + 1],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\t});\n});\n"
  },
  {
    "path": "test/common/fake-machine.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst described_singleton = require('common/fake-machine');\n\ndescribe(described_singleton.constructor.name, function() {\n\tbeforeEach(() => described_singleton.reset());\n\tafter(() => described_singleton.reset());\n\n\tdescribe('.mac_address', function() {\n\t\tconst subject = () => described_singleton.mac_address;\n\n\t\tit('returns a 6 byte address', function() {\n\t\t\texpect(subject()).to.be.a('Uint8Array');\n\t\t\texpect(subject()).to.have.length(6);\n\t\t});\n\n\t\tit('sets the multicast bit', function() {\n\t\t\texpect(subject()[0]).to.satisfy((num) => (num & 0b00000001))\n\t\t});\n\n\t\tit('returns the same value every time', function() {\n\t\t\texpect(subject()).to.deep.equal(subject());\n\t\t});\n\n\t\tit('returns a new value after a reset', function() {\n\t\t\tconst original = subject();\n\t\t\tdescribed_singleton.reset();\n\t\t\texpect(subject()).not.to.deep.equal(original);\n\t\t});\n\t});\n});\n"
  },
  {
    "path": "test/common/machine.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst Os = require('os') || {};\nconst Sinon = require('sinon');\nconst ByteArray = require('common/byte-array');\nconst FakeMachine = require('common/fake-machine');\n\nconst described_singleton = require('common/machine');\n\ndescribe(described_singleton.constructor.name, function() {\n\tbeforeEach(() => described_singleton.reset());\n\tafter(() => described_singleton.reset());\n\n\tdescribe('.mac_address', function() {\n\t\tconst subject = () => described_singleton.mac_address;\n\n\t\tfunction assertFaked() {\n\t\t\tit('returns a 6 byte address', function() {\n\t\t\t\texpect(subject()).to.be.a('Uint8Array');\n\t\t\t\texpect(subject()).to.have.length(6);\n\t\t\t});\n\n\t\t\tit('sets the multicast bit', function() {\n\t\t\t\texpect(subject()[0]).to.satisfy((num) => (num & 0b00000001))\n\t\t\t});\n\n\t\t\tit('returns the same value every time', function() {\n\t\t\t\texpect(subject()).to.deep.equal(subject());\n\t\t\t});\n\n\t\t\tit('returns a new value after a reset', function() {\n\t\t\t\tconst original = subject();\n\t\t\t\tdescribed_singleton.reset();\n\t\t\t\texpect(subject()).not.to.deep.equal(original);\n\t\t\t});\n\t\t}\n\n\t\tlet stubbed_os;\n\t\tbefore(() => (stubbed_os = Sinon.stub(Os, 'networkInterfaces')));\n\t\tbeforeEach(() => stubbed_os.reset());\n\t\tafter(() => stubbed_os.restore());\n\n\t\tit('detects a hardware mac address', function() {\n\t\t\tstubbed_os.callThrough();\n\t\t\tlet is_supported = false;\n\t\t\ttry {\n\t\t\t\tif (ByteArray.compare(subject(), FakeMachine.mac_address)) {\n\t\t\t\t\tis_supported = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (_err) {}\n\n\t\t\tif (! is_supported) {\n\t\t\t\tthis.skip();\n\t\t\t}\n\t\t});\n\n\t\tcontext('when the network interfaces are unavailable', function() {\n\t\t\tbeforeEach(() => stubbed_os.returns([]));\n\n\t\t\tassertFaked();\n\t\t});\n\n\t\tcontext('when the network interfaces are available', function() {\n\t\t\tlet interfaces;\n\t\t\tbeforeEach(() => stubbed_os.returns(interfaces));\n\n\t\t\tcontext('when the interface is internal', function() {\n\t\t\t\tbefore(() => (interfaces = {\n\t\t\t\t\tlo: [{\n\t\t\t\t\t\t\taddress: '127.0.0.1',\n\t\t\t\t\t\t\tnetmask: '255.0.0.0',\n\t\t\t\t\t\t\tfamily: 'IPv4',\n\t\t\t\t\t\t\tmac: '00:00:00:00:00:00',\n\t\t\t\t\t\t\tinternal: true,\n\t\t\t\t\t\t\tcidr: '127.0.0.1/8'\n\t\t\t\t\t}]\n\t\t\t\t}));\n\n\t\t\t\tassertFaked();\n\t\t\t});\n\n\t\t\tcontext('when the interface is missing a mac', function() {\n\t\t\t\tbefore(() => (interfaces = {\n\t\t\t\t\twierd0: [{\n\t\t\t\t\t\taddress: '192.168.1.108',\n\t\t\t\t\t\tnetmask: '255.255.255.0',\n\t\t\t\t\t\tfamily: 'IPv4',\n\t\t\t\t\t\tmac: '',\n\t\t\t\t\t\tinternal: false,\n\t\t\t\t\t\tcidr: '192.168.1.108/24'\n\t\t\t\t\t}]\n\t\t\t\t}));\n\n\t\t\t\tassertFaked();\n\t\t\t});\n\n\t\t\tcontext('when the interface is external and valid', function() {\n\t\t\t\tbefore(() => (interfaces = {\n\t\t\t\t\teth0: [{\n\t\t\t\t\t\taddress: '192.168.1.108',\n\t\t\t\t\t\tnetmask: '255.255.255.0',\n\t\t\t\t\t\tfamily: 'IPv4',\n\t\t\t\t\t\tmac: '01:02:03:0a:0b:0c',\n\t\t\t\t\t\tinternal: false,\n\t\t\t\t\t\tcidr: '192.168.1.108/24'\n\t\t\t\t\t}]\n\t\t\t\t}));\n\n\t\t\t\tit('returns a 6 byte address', function() {\n\t\t\t\t\texpect(subject()).to.be.a('Uint8Array');\n\t\t\t\t\texpect(subject()).to.have.length(6);\n\t\t\t\t});\n\n\t\t\t\tit('returns the same value every time', function() {\n\t\t\t\t\texpect(subject()).to.deep.equal(subject());\n\t\t\t\t});\n\n\t\t\t\tit('return the same value after a reset', function() {\n\t\t\t\t\tconst original = subject();\n\t\t\t\t\tdescribed_singleton.reset();\n\t\t\t\t\texpect(subject()).to.deep.equal(original);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n});\n\n"
  },
  {
    "path": "test/factory/id.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst { IdFactory: described_class } = require('factory/id');\n\nconst id_class = class {\n\tstatic generate() { return new this(`id_${Date.now()}`) }\n\tstatic MIN() { return new this('\\x00') }\n\tstatic MAX() { return new this('\\xFF') }\n\tconstructor(value) { this._bytes = value }\n\tget bytes() { return this._bytes }\n};\n\nconst factory = new described_class({\n\tid: id_class,\n\tcanonical_coder: {\n\t\tencode: (bytes) => `canonical ${bytes}`,\n\t\tencodeTrusted: (bytes) => `canonical ${bytes}`,\n\t\tdecode: (str) => str.replace(/^canonical(?:_distrusted)? /, ''),\n\t\tdecodeTrusted: (str) => str.replace(/^canonical /, ''),\n\t\tisValidEncoding: (str) => /^canonical /.test(str),\n\t},\n\traw_coder: {\n\t\tencode: (bytes) => `raw ${bytes}`,\n\t\tencodeTrusted: (bytes) => `raw ${bytes}`,\n\t\tdecode: (str) => str.replace(/^raw(?:_distrusted)? /, ''),\n\t\tdecodeTrusted: (str) => str.replace(/^raw /, ''),\n\t\tisValidEncoding: (str) => /^raw /.test(str),\n\t},\n});\n\n\nfunction assertDecoder(method, encoding) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method](encoding);\n\n\t\tit('returns an id', function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tassertInjectsInstanceMethod('toCanonical', subject);\n\t\tassertInjectsInstanceMethod('toRaw', subject);\n\t});\n}\n\nfunction assertEncoder(method, pattern) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method](factory.generate());\n\n\t\tit('encodes the bytes of the id', function() {\n\t\t\texpect(subject()).to.match(pattern);\n\t\t});\n\t});\n}\n\nfunction assertGenerator(method) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method]();\n\n\t\tit(`returns an id`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('always returns a different object', function() {\n\t\t\texpect(subject()).not.to.equal(subject());\n\t\t});\n\n\t\tassertInjectsInstanceMethod('toCanonical', subject);\n\t\tassertInjectsInstanceMethod('toRaw', subject);\n\t});\n}\n\nfunction assertInjectsInstanceMethod(injected_method, generator) {\n\tdescribe(injected_method, function() {\n\t\tit(`is injected into the instance`, function() {\n\t\t\tconst id = generator();\n\n\t\t\texpect(() => id[injected_method]()).not.to.throw();\n\t\t\texpect(id[injected_method]()).to.equal(factory[injected_method](id));\n\t\t});\n\n\t\tit('is only injected into the instance', function() {\n\t\t\tconst id = generator();\n\n\t\t\texpect(new id_class()[injected_method]).to.be.undefined;\n\t\t});\n\t});\n}\n\nfunction assertVerifier(method, validEncoding) {\n\tconst conditions = [\n\t\t['canonical', factory.generate().toCanonical()],\n\t\t['raw', factory.generate().toRaw()],\n\t\t['other', 'some random string'],\n\t];\n\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = str => factory[method](str);\n\n\t\tconst {\n\t\t\ttrue: trueConditions,\n\t\t\tfalse: falseConditions,\n\t\t} = conditions.reduce(\n\t\t\t(partitions, condition) => {\n\t\t\t\tconst [name] = condition;\n\t\t\t\tpartitions[validEncoding === name].push(condition);\n\t\t\t\treturn partitions;\n\t\t\t},\n\t\t\t{ true: [], false: [] },\n\t\t);\n\n\t\tit('detects valid encodings', function() {\n\t\t\ttrueConditions.forEach(([name, encoding]) =>\n\t\t\t\texpect(subject(encoding), name).to.be.true);\n\t\t});\n\n\t\tit('rejects invalid encodings', function() {\n\t\t\tfalseConditions.forEach(([name, encoding]) =>\n\t\t\t\texpect(subject(encoding), name).to.be.false);\n\t\t});\n\t});\n}\n\n\ndescribe(described_class.name, function() {\n\tdescribe('#construct', function() {\n\t\tconst subject = () => factory.construct('some bytes');\n\n\t\tit('returns an id', function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('directly stores the bytes', function() {\n\t\t\texpect(subject()).to.have.property('bytes', 'some bytes');\n\t\t});\n\t});\n\n\tdescribe('#name', function() {\n\t\tconst subject = () => factory.name;\n\n\t\tit('returns the name of the id generated by the factory', function() {\n\t\t\texpect(subject()).to.equal(id_class.name);\n\t\t});\n\t});\n\n\tdescribe('#type', function() {\n\t\tconst subject = () => factory.type;\n\n\t\tit('returns the class of the id generated by the factory', function() {\n\t\t\texpect(subject()).to.equal(id_class);\n\t\t});\n\n\t\tit('provides support for the instanceof operator', function() {\n\t\t\texpect(factory.generate()).to.be.an.instanceOf(subject())\n\t\t});\n\t});\n\n\tassertGenerator('generate');\n\tassertGenerator('MIN');\n\tassertGenerator('MAX');\n\n\tassertDecoder('fromCanonical', 'canonical_distrusted some_id');\n\tassertDecoder('fromCanonicalTrusted', 'canonical some_id');\n\tassertDecoder('fromRaw', 'raw_distrusted some_id');\n\tassertDecoder('fromRawTrusted', 'raw some_id');\n\n\tassertEncoder('toCanonical', /^canonical id_\\d+$/);\n\tassertEncoder('toRaw', /^raw id_\\d+$/);\n\n\tassertVerifier('isCanonical', 'canonical');\n\tassertVerifier('isRaw', 'raw');\n});\n\n"
  },
  {
    "path": "test/factory/versioned-id.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst { UnsupportedVersion } = require('common/exception');\n\nconst { VersionedIdFactory: described_class } = require('factory/versioned-id');\n\nconst buildIdClass = (version) => class {\n\tstatic get VERSION() { return version }\n\tstatic generate() { return new this(`id_${Date.now()} vrsn:${this.VERSION}`) }\n\tstatic MIN() { return new this(`\\x00 vrsn:${this.VERSION}`) }\n\tstatic MAX() { return new this(`\\xFF vrsn:${this.VERSION}`) }\n\tconstructor(value) { this._bytes = value }\n\tget bytes() { return this._bytes }\n\tget version() { return /vrsn:(\\w+)/.exec(this._bytes)[1] }\n};\n\nconst version = 'VER';\nconst abstract_id_class = buildIdClass(undefined);\nconst versioned_id_class = buildIdClass(version);\nconst versioned_id_classes = [\n\tbuildIdClass('OTHER1'),\n\tversioned_id_class,\n\tbuildIdClass('OTHER2'),\n];\n\nconst factory = new described_class({\n\tabstract_id: abstract_id_class,\n\tversioned_ids: versioned_id_classes,\n\tcanonical_coder: {\n\t\tencode: (bytes) => `canonical ${bytes}`,\n\t\tencodeTrusted: (bytes) => `canonical ${bytes}`,\n\t\tdecode: (str) => str.replace(/^canonical(?:_distrusted)? /, ''),\n\t\tdecodeTrusted: (str) => str.replace(/^canonical /, ''),\n\t},\n\traw_coder: {\n\t\tencode: (bytes) => `raw ${bytes}`,\n\t\tencodeTrusted: (bytes) => `raw ${bytes}`,\n\t\tdecode: (str) => str.replace(/^raw(?:_distrusted)? /, ''),\n\t\tdecodeTrusted: (str) => str.replace(/^raw /, ''),\n\t},\n});\n\nfunction assertDecoder(method, encoding) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method](encoding);\n\n\t\tit('returns a versioned id', function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(versioned_id_class);\n\t\t});\n\n\t\tit('returns an abstract id when the version is unsupported', function() {\n\t\t\texpect(factory[method](encoding.replace(version, 'IDUNNO')))\n\t\t\t\t.to.be.an.instanceOf(abstract_id_class);\n\t\t});\n\n\t\tassertInjectsInstanceMethod('toCanonical', subject);\n\t\tassertInjectsInstanceMethod('toRaw', subject);\n\t});\n}\n\nfunction assertEncoder(method, pattern) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method](factory.generate({ version }));\n\n\t\tit('encodes the bytes of the id', function() {\n\t\t\texpect(subject()).to.match(pattern);\n\t\t});\n\t});\n}\n\nfunction assertGenerator(method) {\n\tdescribe(`#${method}`, function() {\n\t\tconst subject = () => factory[method]({ version });\n\n\t\tit(`returns a versioned id`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(versioned_id_class);\n\t\t});\n\n\t\tit('always returns a different object', function() {\n\t\t\texpect(subject()).not.to.equal(subject());\n\t\t});\n\n\t\tit('throws without a version', function() {\n\t\t\texpect(() => factory[method]()).to.throw(UnsupportedVersion);\n\t\t});\n\n\t\tassertInjectsInstanceMethod('toCanonical', subject);\n\t\tassertInjectsInstanceMethod('toRaw', subject);\n\t});\n}\n\nfunction assertInjectsInstanceMethod(injected_method, generator) {\n\tdescribe(injected_method, function() {\n\t\tit(`is injected into the instance`, function() {\n\t\t\tconst id = generator();\n\n\t\t\texpect(() => id[injected_method]()).not.to.throw();\n\t\t\texpect(id[injected_method]()).to.equal(factory[injected_method](id));\n\t\t});\n\n\t\tit('is only injected into the instance', function() {\n\t\t\tconst id = generator();\n\n\t\t\texpect(new versioned_id_class()[injected_method]).to.be.undefined;\n\t\t});\n\t});\n}\n\ndescribe(described_class.name, function() {\n\tdescribe('#construct', function() {\n\t\tconst subject = () => factory.construct(`some bytes vrsn:${version}`);\n\n\t\tit('returns a versioned id', function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(versioned_id_class);\n\t\t});\n\n\t\tit('directly stores the bytes', function() {\n\t\t\texpect(subject()).to.have.property('bytes', `some bytes vrsn:${version}`);\n\t\t});\n\n\t\tit('returns an abstract id when the version is unsupported', function() {\n\t\t\texpect(factory.construct('some bytes vrsn:IDUNNO'))\n\t\t\t\t.to.be.an.instanceOf(abstract_id_class);\n\t\t});\n\t});\n\n\tdescribe('#name', function() {\n\t\tconst subject = () => factory.name;\n\n\t\tit('returns the name of the abstract id for the factory', function() {\n\t\t\texpect(subject()).to.equal(abstract_id_class.name);\n\t\t});\n\t});\n\n\tdescribe('#versioned_ids', function() {\n\t\tconst subject = () => factory.versioned_ids;\n\n\t\tit('returns all the versioned id classes the factory can generate', function() {\n\t\t\texpect(subject().map(id => id.name))\n\t\t\t\t.to.have.members(versioned_id_classes.map(id => id.name));\n\t\t});\n\t});\n\n\tassertGenerator('generate');\n\tassertGenerator('MIN');\n\tassertGenerator('MAX');\n\n\tassertDecoder('fromCanonical', `canonical_distrusted some_id vrsn:${version}`);\n\tassertDecoder('fromCanonicalTrusted', `canonical some_id vrsn:${version}`);\n\tassertDecoder('fromRaw', `raw_distrusted some_id vrsn:${version}`);\n\tassertDecoder('fromRawTrusted', `raw some_id vrsn:${version}`);\n\n\tassertEncoder('toCanonical', new RegExp(`^canonical id_\\\\d+ vrsn:${version}$`));\n\tassertEncoder('toRaw', new RegExp(`^raw id_\\\\d+ vrsn:${version}$`));\n});\n\n\n"
  },
  {
    "path": "test/id/shared.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst ByteArray = require('common/byte-array');\nconst Machine = require('common/machine');\n\nconst extractId = ([_, id]) => id;\nconst extractLabel = ([label, _]) => label;\n\nfunction assertAccessorBytes(described_class) {\n\tdescribe('#bytes', function() {\n\t\tconst subject = (bytes) => new described_class(bytes).bytes;\n\n\t\tit('returns the bytes given to the constructor', function() {\n\t\t\t[\n\t\t\t\tByteArray.generateZeroFilled(),\n\t\t\t\tByteArray.generateRandomFilled(),\n\t\t\t\tByteArray.generateOneFilled(),\n\t\t\t].forEach((bytes) => expect(subject(bytes)).to.deep.equal(bytes));\n\t\t});\n\t});\n}\n\nfunction assertAccessorNode(described_class) {\n\tdescribe('#node', function() {\n\t\tconst subject = (node) => described_class.generate({ node }).node;\n\n\t\tit('returns the mac address by default', function() {\n\t\t\texpect(subject()).to.deep.equal(Machine.mac_address);\n\t\t});\n\n\t\tit('returns the supplied node', function() {\n\t\t\tconst node = Uint8Array.of(1, 2, 3, 4, 5, 6);\n\t\t\texpect(subject(node)).to.deep.equal(node);\n\t\t});\n\t});\n}\n\nfunction assertAccessorTime(described_class, labeled_times) {\n\tdescribe('#time', function() {\n\t\tconst subject = (time) => described_class.generate({ time }).time;\n\n\t\tit('returns the time given to generate', function() {\n\t\t\tlabeled_times.forEach(([label, time]) => {\n\t\t\t\texpect(subject(time), label).to.deep.equal(time)\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction assertCompareDemonstratesTotalOrder(labeled_ids) {\n\tdescribe('#compare', function() {\n\t\tconst diagnose = (lhs, rhs) => `(${lhs}).compare(${rhs})`;\n\n\t\tlabeled_ids.forEach(([lhs_label, lhs_id], lhs_idx) => {\n\t\t\tconst subject = (other) => lhs_id.compare(other.clone());\n\t\t\tconst prev_ids = labeled_ids.filter((_, idx) => (idx < lhs_idx));\n\t\t\tconst next_ids = labeled_ids.filter((_, idx) => (idx > lhs_idx));\n\n\t\t\tdescribe(`given ${lhs_label}`, function() {\n\t\t\t\tif (lhs_idx === labeled_ids.length - 1) {\n\t\t\t\t\tit('has no subsequent ids', function() {\n\t\t\t\t\t\texpect(next_ids, `${lhs_label} should be the last id`).to.be.empty;\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tit('returns -1 for all subsequent ids', function() {\n\t\t\t\t\t\tnext_ids.forEach(([label, id]) => {\n\t\t\t\t\t\t\texpect(subject(id), diagnose(lhs_label, label)).to.equal(-1);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tit('returns 0 for itself', function() {\n\t\t\t\t\tconst [label, id] = labeled_ids[lhs_idx];\n\t\t\t\t\texpect(subject(id), label).to.equal(0);\n\t\t\t\t});\n\n\t\t\t\tif (lhs_idx === 0) {\n\t\t\t\t\tit('has no previous ids', function() {\n\t\t\t\t\t\texpect(prev_ids, `${lhs_label} should be the first id`).to.be.empty;\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tit('returns 1 for all previous ids', function() {\n\t\t\t\t\t\tprev_ids.forEach(([label, id]) => {\n\t\t\t\t\t\t\texpect(subject(id), diagnose(lhs_label, label)).to.equal(1);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction assertDebuggable(described_class) {\n\tdescribe('when cast as a string', function() {\n\t\tconst subject = () => '' + new described_class();\n\n\t\tit(`mentions the type ${described_class.name}`, function() {\n\t\t\texpect(subject()).to.contain.string(described_class.name);\n\t\t});\n\t});\n}\n\nfunction assertEqualDemonstratesSameness(labeled_ids) {\n\tdescribe('#equal', function() {\n\t\tconst diagnose = (lhs, rhs) => `(${lhs}).equal(${rhs})`;\n\n\t\tlabeled_ids.forEach(([lhs_label, lhs_id]) => {\n\t\t\tconst subject = (other) => lhs_id.equal(other.clone());\n\n\t\t\tdescribe(`given ${lhs_label}`, function() {\n\t\t\t\tit('returns true for itself', function() {\n\t\t\t\t\texpect(subject(lhs_id)).to.be.true;\n\t\t\t\t});\n\n\t\t\t\tit('returns false for all others', function() {\n\t\t\t\t\tlabeled_ids\n\t\t\t\t\t\t.filter((pair) => extractId(pair) !== lhs_id)\n\t\t\t\t\t\t.forEach(([label, id]) => {\n\t\t\t\t\t\t\texpect(subject(id), diagnose(lhs_label, label)).to.be.false\n\t\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction assertGenerateBasics(described_class) {\n\tdescribe('.generate', function() {\n\t\tconst subject = () => described_class.generate();\n\n\t\tit(`returns a new ${described_class.name}`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(described_class);\n\t\t});\n\n\t\tit(`returns an id with different bytes each time`, function() {\n\t\t\t// NOTE: given the nature of random and the bit entropy,\n\t\t\t// we're guarding against extreme misfortune\n\t\t\tthis.retries(2);\n\n\t\t\texpect(subject().bytes).not.to.deep.equal(subject().bytes);\n\t\t});\n\t});\n}\n\nfunction assertUuidVariantVersion(described_class, variant, version) {\n\tconst assertVariant = (subject) => it(`is variant ${variant}`, function() {\n\t\texpect(subject().variant).to.eql(variant);\n\t});\n\tconst assertVersion = (subject) => it(`is version ${version}`, function() {\n\t\texpect(subject().version).to.eql(version);\n\t});\n\n\tdescribe('.generate variant/version', function() {\n\t\tconst subject = () => described_class.generate();\n\n\t\tassertVariant(subject);\n\t\tassertVersion(subject);\n\t});\n\n\tdescribe('.MIN variant/version', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tassertVariant(subject);\n\t\tassertVersion(subject);\n\t});\n\n\tdescribe('.MAX variant/version', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tassertVariant(subject);\n\t\tassertVersion(subject);\n\t});\n}\n\nmodule.exports = {\n\tassertAccessorBytes,\n\tassertAccessorNode,\n\tassertAccessorTime,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n\tassertUuidVariantVersion,\n};\n"
  },
  {
    "path": "test/id/ulid-monotonic.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\nconst {\n\tClockSequenceOverflow,\n\tInvalidEpoch,\n} = require('common/exception');\n\nconst { UlidMonotonic: described_class } = require('id/ulid-monotonic');\n\nconst MAX_TIME = new Date(Math.pow(2, 48) - 1);\nconst MIN_TIME = new Date(0);\n\ndescribe(described_class.name, function() {\n\tbeforeEach(() => described_class.reset());\n\tafter(() => described_class.reset());\n\n\tassertDebuggable(described_class);\n\n\tassertGenerateBasics(described_class);\n\tdescribe('.generate extended', function() {\n\t\tconst subject = (time) => described_class.generate({ time });\n\n\t\tit('accepts epoch values', function() {\n\t\t\t[\n\t\t\t\t['start of epoch', MIN_TIME],\n\t\t\t\t['end of epoch', MAX_TIME],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects pre/post-epoch values', function() {\n\t\t\t[\n\t\t\t\t['prior to 1970', MIN_TIME - 1],\n\t\t\t\t['after late 10889', MAX_TIME + 1],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('throws when the clock sequence overflows', function() {\n\t\t\tconst overflow = 0x10001;\n\t\t\tlet sequence = 0;\n\n\t\t\tsubject(Date.now() + 24 * 60 * 60 * 1000);\n\t\t\texpect(() => {\n\t\t\t\tfor (; sequence <= overflow; ++sequence) {\n\t\t\t\t\tsubject();\n\t\t\t\t}\n\t\t\t}).to.throw(ClockSequenceOverflow);\n\t\t\texpect(sequence).to.be.above(overflow >> 1);\n\t\t\texpect(sequence).to.be.below(overflow);\n\t\t});\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits', function() {\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateZeroFilled());\n\t\t});\n\n\t\tit('has the least allowed time', function() {\n\t\t\texpect(subject().time).to.deep.equal(MIN_TIME);\n\t\t});\n\n\t\tit('ignores monotonicity', function() {\n\t\t\tsubject();\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateZeroFilled());\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 1-bits', function() {\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateOneFilled());\n\t\t});\n\n\t\tit('has the greatest allowed time', function() {\n\t\t\texpect(subject().time).to.deep.equal(MAX_TIME);\n\t\t});\n\n\t\tit('ignores monotonicity', function() {\n\t\t\tsubject();\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateOneFilled());\n\t\t});\n\t});\n\n\tassertAccessorBytes(described_class);\n\tdescribe('#time', function() {\n\t\tconst subject = (time) => described_class.generate({ time }).time;\n\n\t\tdescribe('given a future time', function() {\n\t\t\tit('returns the time given to generate', function() {\n\t\t\t\t[\n\t\t\t\t\t['min', MIN_TIME],\n\t\t\t\t\t['now', new Date()],\n\t\t\t\t\t['max', MAX_TIME],\n\t\t\t\t].forEach(([label, time]) => {\n\t\t\t\t\texpect(subject(time), label).to.deep.equal(time);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tdescribe('given a past time', function() {\n\t\t\tlet most_recent_time;\n\t\t\tbeforeEach(() => (most_recent_time = subject(MAX_TIME)));\n\n\t\t\tit('returns the same time as the most recent id', function() {\n\t\t\t\t[\n\t\t\t\t\t['min', MIN_TIME],\n\t\t\t\t\t['now', new Date()],\n\t\t\t\t\t['max', MAX_TIME],\n\t\t\t\t].forEach(([label, time]) => {\n\t\t\t\t\texpect(subject(time), label).to.deep.equal(most_recent_time);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n\n\tassertCompareDemonstratesTotalOrder([\n\t\t['the min id', described_class.MIN()],\n\t\t['a min time id', described_class.generate({ time: MIN_TIME })],\n\t\t['a recent id', described_class.generate({ time: new Date })],\n\t\t['a max time id', described_class.generate({ time: MAX_TIME })],\n\t\t['an anachronistic id', described_class.generate({ time: new Date })],\n\t\t['the max id', described_class.MAX()],\n\t]);\n\n\tassertEqualDemonstratesSameness([\n\t\t['the min id', described_class.MIN()],\n\t\t['a min time id', described_class.generate({ time: MIN_TIME })],\n\t\t['a recent id', described_class.generate({ time: new Date() })],\n\t\t['a max time id', described_class.generate({ time: MAX_TIME })],\n\t\t['an anachronistic id', described_class.generate({ time: new Date() })],\n\t\t['the max id', described_class.MAX()],\n\t]);\n});\n"
  },
  {
    "path": "test/id/ulid.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertAccessorTime,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\nconst { InvalidEpoch } = require('common/exception');\n\nconst { Ulid: described_class } = require('id/ulid');;\n\nconst MAX_TIME = new Date(Math.pow(2, 48) - 1);\nconst MIN_TIME = new Date(0);\n\ndescribe(described_class.name, function() {\n\tassertDebuggable(described_class);\n\n\tassertGenerateBasics(described_class);\n\tdescribe('.generate extended', function() {\n\t\tconst subject = (time) => described_class.generate({ time });\n\n\t\tit('accepts epoch values', function() {\n\t\t\t[\n\t\t\t\t['start of epoch', MIN_TIME],\n\t\t\t\t['end of epoch', MAX_TIME],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects pre/post-epoch values', function() {\n\t\t\t[\n\t\t\t\t['prior to 1970', MIN_TIME - 1],\n\t\t\t\t['after late 10889', MAX_TIME + 1],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits', function() {\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateZeroFilled());\n\t\t});\n\n\t\tit('has the least allowed time', function() {\n\t\t\texpect(subject().time).to.deep.equal(MIN_TIME);\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 1-bits', function() {\n\t\t\texpect(subject().bytes).to.deep.equal(ByteArray.generateOneFilled());\n\t\t});\n\n\t\tit('has the greatest allowed time', function() {\n\t\t\texpect(subject().time).to.deep.equal(MAX_TIME);\n\t\t});\n\t});\n\n\tassertAccessorBytes(described_class);\n\tassertAccessorTime(described_class, [\n\t\t['min', MIN_TIME],\n\t\t['now', new Date()],\n\t\t['max', MAX_TIME],\n\t]);\n\n\tassertCompareDemonstratesTotalOrder([\n\t\t['the min id', described_class.MIN()],\n\t\t['a min time id', described_class.generate({ time: MIN_TIME })],\n\t\t['a recent id', described_class.generate({ time: new Date })],\n\t\t['a max time id', described_class.generate({ time: MAX_TIME })],\n\t\t['the max id', described_class.MAX()],\n\t]);\n\n\tassertEqualDemonstratesSameness([\n\t\t['the min id', described_class.MIN()],\n\t\t['a min time id', described_class.generate({ time: MIN_TIME })],\n\t\t['a recent id', described_class.generate({ time: new Date })],\n\t\t['a max time id', described_class.generate({ time: MAX_TIME })],\n\t\t['the max id', described_class.MAX()],\n\t]);\n});\n"
  },
  {
    "path": "test/id/uuid-1.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertAccessorNode,\n\tassertAccessorTime,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n\tassertUuidVariantVersion,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\nconst { InvalidEpoch } = require('common/exception');\n\nconst { Uuid1: described_class } = require('id/uuid-1');\n\nconst ORIGIN = Date.parse('1582-10-15Z');\nconst MAX_TIME = new Date(Math.pow(2, 48) - 1 + ORIGIN);\nconst MIN_TIME = new Date(ORIGIN);\n\ndescribe(described_class.name, function() {\n\tbeforeEach(() => described_class.reset());\n\tafter(() => described_class.reset());\n\n\tassertDebuggable(described_class);\n\tassertGenerateBasics(described_class);\n\tdescribe('.generate extended', function() {\n\t\tconst CLOCK_MAX = 0x3FFF;\n\t\tconst HIRES_MAX = 0x0FFF;\n\t\tconst subject = (time) => described_class.generate({ time });\n\n\t\tit('accepts epoch values', function() {\n\t\t\t[\n\t\t\t\t['start of epoch', MIN_TIME],\n\t\t\t\t['end of epoch', MAX_TIME],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects pre/post-epoch values', function() {\n\t\t\t[\n\t\t\t\t['prior to Gregorian calendar', MIN_TIME - 1],\n\t\t\t\t['after late 10502', MAX_TIME + 1],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given a time in the past', function() {\n\t\t\tit('increments the hires timer', function() {\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MIN_TIME).hires_time)\n\t\t\t\t\t.to.equal(previous_id.hires_time + 1);\n\t\t\t});\n\n\t\t\tit('increments the clock sequence', function() {\n\t\t\t\t// For the minor chance that the clock sequence starts at the top\n\t\t\t\tthis.retries(1);\n\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MIN_TIME).clock_sequence)\n\t\t\t\t\t.to.equal(previous_id.clock_sequence + 1);\n\t\t\t});\n\n\t\t\tcontext('when the clock sequence overflows', function() {\n\t\t\t\tfunction clockOverflow(time) {\n\t\t\t\t\tfor (let count = 0; count < CLOCK_MAX; ++count) {\n\t\t\t\t\t\tsubject(time);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tit('resets the clock sequence', function() {\n\t\t\t\t\tsubject();\n\t\t\t\t\tclockOverflow(MIN_TIME);\n\t\t\t\t\texpect(subject(MIN_TIME).hires_time).to.equal(0);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given the same time', function() {\n\t\t\tconst time = Date.now();\n\n\t\t\tit('increments the hires timer', function() {\n\t\t\t\tconst previous_id = subject(time);\n\t\t\t\texpect(subject(time).hires_time).to.equal(previous_id.hires_time + 1);\n\t\t\t});\n\n\t\t\tcontext('when the hires timer overflows', function() {\n\t\t\t\tfunction hiresOverflow(time) {\n\t\t\t\t\tfor (let count = 0; count < HIRES_MAX; ++count) {\n\t\t\t\t\t\tsubject(time);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tit('resets the hires timer', function() {\n\t\t\t\t\tsubject();\n\t\t\t\t\thiresOverflow(time);\n\t\t\t\t\texpect(subject(time).hires_time).to.equal(0);\n\t\t\t\t});\n\n\t\t\t\tit('increments the clock sequence', function() {\n\t\t\t\t\t// For the minor chance that the clock sequence starts at the top\n\t\t\t\t\tthis.retries(1);\n\n\t\t\t\t\tconst previous_id = subject(time);\n\t\t\t\t\thiresOverflow(time);\n\t\t\t\t\texpect(subject(time).clock_sequence)\n\t\t\t\t\t\t.to.equal(previous_id.clock_sequence + 1);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given a time in the future', function() {\n\t\t\tit('resets the hires timer', function() {\n\t\t\t\tsubject();\n\t\t\t\texpect(subject(MAX_TIME).hires_time).to.equal(0);\n\t\t\t});\n\n\t\t\tit('retains the same clock sequence', function() {\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MAX_TIME).clock_sequence)\n\t\t\t\t\t.to.equal(previous_id.clock_sequence);\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateZeroFilled();\n\t\t\texpected.set([0b00010000], 6);\n\t\t\texpected.set([0b10000000], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 1-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateOneFilled();\n\t\t\texpected.set([0b00011111], 6);\n\t\t\texpected.set([0b10111111], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tassertUuidVariantVersion(described_class, 1, 1);\n\tassertAccessorBytes(described_class);\n\tassertAccessorNode(described_class);\n\tassertAccessorTime(described_class, [\n\t\t['min', MIN_TIME],\n\t\t['origin', new Date(0)],\n\t\t['now', new Date()],\n\t\t['max', MAX_TIME],\n\t]);\n\n\tassertCompareDemonstratesTotalOrder([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n\n\tassertEqualDemonstratesSameness([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n});\n\n"
  },
  {
    "path": "test/id/uuid-4.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n\tassertUuidVariantVersion,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\n\nconst { Uuid4: described_class } = require('id/uuid-4');\n\ndescribe(described_class.name, function() {\n\tassertDebuggable(described_class);\n\tassertGenerateBasics(described_class);\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateZeroFilled();\n\t\t\texpected.set([0b01000000], 6);\n\t\t\texpected.set([0b10000000], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 1-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateOneFilled();\n\t\t\texpected.set([0b01001111], 6);\n\t\t\texpected.set([0b10111111], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tassertUuidVariantVersion(described_class, 1, 4);\n\tassertAccessorBytes(described_class);\n\n\tassertCompareDemonstratesTotalOrder([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n\n\tassertEqualDemonstratesSameness([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n});\n"
  },
  {
    "path": "test/id/uuid-6.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertAccessorNode,\n\tassertAccessorTime,\n\tassertCompareDemonstratesTotalOrder,\n\tassertDebuggable,\n\tassertEqualDemonstratesSameness,\n\tassertGenerateBasics,\n\tassertUuidVariantVersion,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\nconst { InvalidEpoch } = require('common/exception');\n\nconst { Uuid6: described_class } = require('id/uuid-6');\n\nconst ORIGIN = Date.parse('1582-10-15Z');\nconst MAX_TIME = new Date(Math.pow(2, 48) - 1 + ORIGIN);\nconst MIN_TIME = new Date(ORIGIN);\n\ndescribe(described_class.name, function() {\n\tbeforeEach(() => described_class.reset());\n\tafter(() => described_class.reset());\n\n\tassertDebuggable(described_class);\n\tassertGenerateBasics(described_class);\n\tdescribe('.generate extended', function() {\n\t\tconst CLOCK_MAX = 0x3FFF;\n\t\tconst HIRES_MAX = 0x0FFF;\n\t\tconst subject = (time) => described_class.generate({ time });\n\n\t\tit('accepts epoch values', function() {\n\t\t\t[\n\t\t\t\t['start of epoch', MIN_TIME],\n\t\t\t\t['end of epoch', MAX_TIME],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).not.to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tit('rejects pre/post-epoch values', function() {\n\t\t\t[\n\t\t\t\t['prior to Gregorian calendar', MIN_TIME - 1],\n\t\t\t\t['after late 10502', MAX_TIME + 1],\n\t\t\t].forEach(([label, value]) => {\n\t\t\t\texpect(() => subject(value), label).to.throw(InvalidEpoch);\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given a time in the past', function() {\n\t\t\tit('increments the hires timer', function() {\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MIN_TIME).hires_time)\n\t\t\t\t\t.to.equal(previous_id.hires_time + 1);\n\t\t\t});\n\n\t\t\tit('increments the clock sequence', function() {\n\t\t\t\t// For the minor chance that the clock sequence starts at the top\n\t\t\t\tthis.retries(1);\n\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MIN_TIME).clock_sequence)\n\t\t\t\t\t.to.equal(previous_id.clock_sequence + 1);\n\t\t\t});\n\n\t\t\tcontext('when the clock sequence overflows', function() {\n\t\t\t\tfunction clockOverflow(time) {\n\t\t\t\t\tfor (let count = 0; count < CLOCK_MAX; ++count) {\n\t\t\t\t\t\tsubject(time);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tit('resets the clock sequence', function() {\n\t\t\t\t\tsubject();\n\t\t\t\t\tclockOverflow(MIN_TIME);\n\t\t\t\t\texpect(subject(MIN_TIME).hires_time).to.equal(0);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given the same time', function() {\n\t\t\tconst time = Date.now();\n\n\t\t\tit('increments the hires timer', function() {\n\t\t\t\tconst previous_id = subject(time);\n\t\t\t\texpect(subject(time).hires_time).to.equal(previous_id.hires_time + 1);\n\t\t\t});\n\n\t\t\tcontext('when the hires timer overflows', function() {\n\t\t\t\tfunction hiresOverflow(time) {\n\t\t\t\t\tfor (let count = 0; count < HIRES_MAX; ++count) {\n\t\t\t\t\t\tsubject(time);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tit('resets the hires timer', function() {\n\t\t\t\t\tsubject();\n\t\t\t\t\thiresOverflow(time);\n\t\t\t\t\texpect(subject(time).hires_time).to.equal(0);\n\t\t\t\t});\n\n\t\t\t\tit('increments the clock sequence', function() {\n\t\t\t\t\t// For the minor chance that the clock sequence starts at the top\n\t\t\t\t\tthis.retries(1);\n\n\t\t\t\t\tconst previous_id = subject(time);\n\t\t\t\t\thiresOverflow(time);\n\t\t\t\t\texpect(subject(time).clock_sequence)\n\t\t\t\t\t\t.to.equal(previous_id.clock_sequence + 1);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\n\t\tcontext('when given a time in the future', function() {\n\t\t\tit('resets the hires timer', function() {\n\t\t\t\tsubject();\n\t\t\t\texpect(subject(MAX_TIME).hires_time).to.equal(0);\n\t\t\t});\n\n\t\t\tit('retains the same clock sequence', function() {\n\t\t\t\tconst previous_id = subject();\n\t\t\t\texpect(subject(MAX_TIME).clock_sequence)\n\t\t\t\t\t.to.equal(previous_id.clock_sequence);\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateZeroFilled();\n\t\t\texpected.set([0b01100000], 6);\n\t\t\texpected.set([0b10000000], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 1-bits other than variant/version', function() {\n\t\t\tconst expected = ByteArray.generateOneFilled();\n\t\t\texpected.set([0b01101111], 6);\n\t\t\texpected.set([0b10111111], 8);\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tassertUuidVariantVersion(described_class, 1, 6);\n\tassertAccessorBytes(described_class);\n\tassertAccessorNode(described_class);\n\tassertAccessorTime(described_class, [\n\t\t['min', MIN_TIME],\n\t\t['origin', new Date(0)],\n\t\t['now', new Date()],\n\t\t['max', MAX_TIME],\n\t]);\n\n\tassertCompareDemonstratesTotalOrder([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n\n\tassertEqualDemonstratesSameness([\n\t\t['the min id', described_class.MIN()],\n\t\t['a random id', described_class.generate()],\n\t\t['the max id', described_class.MAX()],\n\t]);\n});\n\n"
  },
  {
    "path": "test/id/uuid-nil.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\nconst {\n\tassertAccessorBytes,\n\tassertDebuggable,\n\tassertUuidVariantVersion,\n} = require('./shared');\n\nconst ByteArray = require('common/byte-array');\n\nconst { UuidNil: described_class } = require('id/uuid-nil');\n\ndescribe(described_class.name, function() {\n\tassertDebuggable(described_class);\n\n\tdescribe('.generate', function() {\n\t\tconst subject = () => described_class.generate();\n\n\t\tit(`returns a new ${described_class.name}`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(described_class);\n\t\t});\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => described_class.MIN();\n\n\t\tit('has all 0-bits', function() {\n\t\t\tconst expected = ByteArray.generateZeroFilled();\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => described_class.MAX();\n\n\t\tit('has all 0-bits', function() {\n\t\t\tconst expected = ByteArray.generateZeroFilled();\n\n\t\t\texpect(subject().bytes).to.deep.equal(expected);\n\t\t});\n\t});\n\n\tassertUuidVariantVersion(described_class, 0, 0);\n\tassertAccessorBytes(described_class);\n\n\tdescribe('#compare', function() {\n\t\tconst diagnose = (lhs, rhs) => `(${lhs}).compare(${rhs})`;\n\n\t\tconst labeled_ids = [\n\t\t\t['the min id', described_class.MIN()],\n\t\t\t['a random id', described_class.generate()],\n\t\t\t['another random id', described_class.generate()],\n\t\t\t['the max id', described_class.MAX()],\n\t\t];\n\n\t\tlabeled_ids.forEach(([lhs_label, lhs_id], lhs_idx) => {\n\t\t\tconst subject = (other) => lhs_id.compare(other.clone());\n\n\t\t\tdescribe(`given ${lhs_label}`, function() {\n\t\t\t\tit('returns 0 for all ids', function() {\n\t\t\t\t\tlabeled_ids.forEach(([label, id]) => {\n\t\t\t\t\t\texpect(subject(id), diagnose(lhs_label, label)).to.equal(0);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n\n\tdescribe('#equal', function() {\n\t\tconst diagnose = (lhs, rhs) => `(${lhs}).equal(${rhs})`;\n\n\t\tconst labeled_ids = [\n\t\t\t['the min id', described_class.MIN()],\n\t\t\t['a random id', described_class.generate()],\n\t\t\t['another random id', described_class.generate()],\n\t\t\t['the max id', described_class.MAX()],\n\t\t];\n\n\t\tlabeled_ids.forEach(([lhs_label, lhs_id]) => {\n\t\t\tconst subject = (other) => lhs_id.equal(other.clone());\n\n\t\t\tdescribe(`given ${lhs_label}`, function() {\n\t\t\t\tit('returns true for all ids', function() {\n\t\t\t\t\tlabeled_ids.forEach(([label, id]) => {\n\t\t\t\t\t\texpect(subject(id), diagnose(lhs_label, label)).to.be.true;\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t});\n});\n\n"
  },
  {
    "path": "test/id128.js",
    "content": "'use strict';\n\nconst { expect } = require('chai');\n\nconst Id128 = require('../');\n\nfunction assertDebuggable(id_name, generator) {\n\tdescribe('when cast as a string', function() {\n\t\tconst subject = () => '' + generator();\n\n\t\tit(`mentions the type ${id_name}`, function() {\n\t\t\texpect(subject()).to.contain.string(id_name);\n\t\t});\n\t});\n}\n\nfunction assertValidId128(id_name, factory, id_class, generator_args = {}) {\n\tdescribe('new', function() {\n\t\tit('is disabled', function() {\n\t\t\texpect(() => new factory).to.throw(TypeError);\n\t\t});\n\t});\n\n\tdescribe('.generate', function() {\n\t\tconst subject = () => factory.generate(generator_args);\n\n\t\tit(`returns a ${id_name}`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t\texpect(subject()).to.be.an.instanceOf(factory.type);\n\t\t});\n\n\t\tit('generates 128-bit id', function() {\n\t\t\texpect(subject().bytes).to.have.lengthOf(16);\n\t\t});\n\n\t\tassertDebuggable(id_name, subject);\n\t});\n\n\tdescribe('.MIN', function() {\n\t\tconst subject = () => factory.MIN(generator_args);\n\n\t\tit(`returns a ${id_name}`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('generates 128-bit id', function() {\n\t\t\texpect(subject().bytes).to.have.lengthOf(16);\n\t\t});\n\n\t\tassertDebuggable(id_name, subject);\n\t});\n\n\tdescribe('.MAX', function() {\n\t\tconst subject = () => factory.MAX(generator_args);\n\n\t\tit(`returns a ${id_name}`, function() {\n\t\t\texpect(subject()).to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('generates 128-bit id', function() {\n\t\t\texpect(subject().bytes).to.have.lengthOf(16);\n\t\t});\n\n\t\tassertDebuggable(id_name, subject);\n\t});\n\n\tdescribe('canonical', function() {\n\t\tconst id = factory.generate(generator_args);\n\n\t\tit('encodes to a string', function() {\n\t\t\texpect(factory.toCanonical(id)).to.be.a('string');\n\t\t});\n\n\t\tit(`decodes to a ${id_name}`, function() {\n\t\t\texpect(factory.fromCanonical(factory.toCanonical(id)))\n\t\t\t\t.to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('converts symmetrically', function() {\n\t\t\t[\n\t\t\t\t['generated', id],\n\t\t\t\t['min', factory.MIN(generator_args)],\n\t\t\t\t['max', factory.MAX(generator_args)],\n\t\t\t].forEach(([label, test_id]) => {\n\t\t\t\texpect(factory.fromCanonical(factory.toCanonical(test_id)), label)\n\t\t\t\t\t.to.deep.equal(test_id);\n\t\t\t});\n\t\t});\n\n\t\tdescribe('when decoded', function() {\n\t\t\tassertDebuggable(id_name, () => factory.fromCanonical(id.toCanonical()));\n\t\t});\n\t});\n\n\tdescribe('raw', function() {\n\t\tconst id = factory.generate(generator_args);\n\n\t\tit('encodes to a string', function() {\n\t\t\texpect(factory.toRaw(id)).to.be.a('string');\n\t\t});\n\n\t\tit(`decodes to a ${id_name}`, function() {\n\t\t\texpect(factory.fromRaw(factory.toRaw(id)))\n\t\t\t\t.to.be.an.instanceOf(id_class);\n\t\t});\n\n\t\tit('converts symmetrically', function() {\n\t\t\t[\n\t\t\t\t['generated', id],\n\t\t\t\t['min', factory.MIN(generator_args)],\n\t\t\t\t['max', factory.MAX(generator_args)],\n\t\t\t].forEach(([label, test_id]) => {\n\t\t\t\texpect(factory.fromRaw(factory.toRaw(test_id)), label)\n\t\t\t\t\t.to.deep.equal(test_id);\n\t\t\t});\n\t\t});\n\n\t\tdescribe('when decoded', function() {\n\t\t\tassertDebuggable(id_name, () => factory.fromRaw(id.toRaw()));\n\t\t});\n\t});\n}\n\n[\n\t'Ulid',\n\t'UlidMonotonic',\n\t'Uuid1',\n\t'Uuid4',\n\t'UuidNil',\n].forEach((id_name) => describe(`${id_name} Factory`, function() {\n\tassertValidId128(\n\t\tid_name,\n\t\tId128[id_name],\n\t\tId128[id_name].type,\n\t);\n}));\n\n[\n\t['Uuid1', { version: 1 }],\n\t['Uuid4', { version: 4 }],\n\t['Uuid6', { version: 6 }],\n\t['UuidNil', { version: 0 }],\n].forEach(([id_name, generator_args]) => {\n\tdescribe(`Uuid Factory generating ${id_name}`, function() {\n\t\tassertValidId128(\n\t\t\tid_name,\n\t\t\tId128.Uuid,\n\t\t\tId128[id_name].type,\n\t\t\tgenerator_args,\n\t\t);\n\t});\n});\n\n\nconst all_ids = [\n\t'Ulid',\n\t'UlidMonotonic',\n\t'Uuid1',\n\t'Uuid4',\n\t'UuidNil',\n].map((id_name) => Id128[id_name].generate())\n\ndescribe('idCompare', function() {\n\tconst subject = Id128.idCompare\n\n\tit('compares the same id of any type', function() {\n\t\tall_ids.forEach((id) => expect(subject(id, id), id.name).to.equal(0));\n\t});\n\n\tit('works with ids of any type', function() {\n\t\tall_ids.forEach((lhs) => {\n\t\t\tall_ids.forEach((rhs) => {\n\t\t\t\texpect(() => subject(lhs, rhs), `${lhs.name} and ${rhs.name}`)\n\t\t\t\t\t.not.to.throw();\n\t\t\t});\n\t\t});\n\t});\n})\n\ndescribe('idEqual', function() {\n\tconst subject = Id128.idEqual\n\n\tit('equates the same id of any type', function() {\n\t\tall_ids.forEach((id) => expect(subject(id, id), id.name).to.equal(true));\n\t});\n\n\tit('works with ids of any type', function() {\n\t\tall_ids.forEach((lhs) => {\n\t\t\tall_ids.forEach((rhs) => {\n\t\t\t\texpect(() => subject(lhs, rhs), `${lhs.name} and ${rhs.name}`)\n\t\t\t\t\t.not.to.throw();\n\t\t\t});\n\t\t});\n\t});\n})\n"
  },
  {
    "path": "types/test.ts",
    "content": "import {\n\tidCompare,\n\tidEqual,\n\tException,\n\tUlid,\n\tUlidMonotonic,\n\tUuid,\n\tUuid1,\n\tUuid4,\n\tUuid6,\n\tUuidNil,\n} from 'id128';\n\nconst bytes = new Uint8Array(16);\nconst encoded_id = \"encoded-id-data\";\nconst node = new Uint8Array([]);\nconst now = new Date();\n\nconst ulid = Ulid.MIN();\nconst ulid_monotonic = UlidMonotonic.MIN();\nconst uuid = Uuid.MIN({ version: 0 });\nconst uuid_1 = Uuid1.MIN();\nconst uuid_4 = Uuid4.MIN();\nconst uuid_6 = Uuid6.MIN();\nconst uuid_nil = UuidNil.MIN();\n\nUlid.MAX(); // $ExpectType Ulid\nUlid.MIN(); // $ExpectType Ulid\nUlid.construct(bytes); // $ExpectType Ulid\nUlid.fromCanonical(encoded_id); // $ExpectType Ulid\nUlid.fromCanonicalTrusted(encoded_id); // $ExpectType Ulid\nUlid.fromRaw(encoded_id); // $ExpectType Ulid\nUlid.fromRawTrusted(encoded_id); // $ExpectType Ulid\nUlid.generate(); // $ExpectType Ulid\nUlid.generate({ time: now }); // $ExpectType Ulid\nUlid.generate({}); // $ExpectType Ulid\nUlid.isCanonical(encoded_id); // $ExpectType boolean\nUlid.isRaw(encoded_id); // $ExpectType boolean\nUlid.name; // $ExpectType string\nUlid.type; // $ExpectType ConstructorOf<Ulid>\nUlid.toCanonical(ulid); // $ExpectType string\nUlid.toRaw(ulid); // $ExpectType string\n\nUlidMonotonic.MAX(); // $ExpectType UlidMonotonic\nUlidMonotonic.MIN(); // $ExpectType UlidMonotonic\nUlidMonotonic.construct(bytes); // $ExpectType UlidMonotonic\nUlidMonotonic.fromCanonical(encoded_id); // $ExpectType UlidMonotonic\nUlidMonotonic.fromCanonicalTrusted(encoded_id); // $ExpectType UlidMonotonic\nUlidMonotonic.fromRaw(encoded_id); // $ExpectType UlidMonotonic\nUlidMonotonic.fromRawTrusted(encoded_id); // $ExpectType UlidMonotonic\nUlidMonotonic.generate(); // $ExpectType UlidMonotonic\nUlidMonotonic.generate({ time: now }); // $ExpectType UlidMonotonic\nUlidMonotonic.generate({}); // $ExpectType UlidMonotonic\nUlidMonotonic.isCanonical(encoded_id); // $ExpectType boolean\nUlidMonotonic.isRaw(encoded_id); // $ExpectType boolean\nUlidMonotonic.name; // $ExpectType string\nUlidMonotonic.type; // $ExpectType ConstructorOf<UlidMonotonic>\nUlidMonotonic.toCanonical(ulid_monotonic); // $ExpectType string\nUlidMonotonic.toRaw(ulid_monotonic); // $ExpectType string\n\nUuid.MAX({ version: 0 }); // $ExpectType Uuid\nUuid.MAX({ version: 1 }); // $ExpectType Uuid\nUuid.MAX({ version: 4 }); // $ExpectType Uuid\nUuid.MAX({ version: 6 }); // $ExpectType Uuid\nUuid.MIN({ version: 0 }); // $ExpectType Uuid\nUuid.MIN({ version: 1 }); // $ExpectType Uuid\nUuid.MIN({ version: 4 }); // $ExpectType Uuid\nUuid.MIN({ version: 6 }); // $ExpectType Uuid\nUuid.fromCanonical(encoded_id); // $ExpectType Uuid\nUuid.fromCanonicalTrusted(encoded_id); // $ExpectType Uuid\nUuid.fromRaw(encoded_id); // $ExpectType Uuid\nUuid.fromRawTrusted(encoded_id); // $ExpectType Uuid\nUuid.generate({ node, time: now, version: 1 }); // $ExpectType Uuid\nUuid.generate({ node, time: now, version: 6 }); // $ExpectType Uuid\nUuid.generate({ version: 0 }); // $ExpectType Uuid\nUuid.generate({ version: 4 }); // $ExpectType Uuid\nUuid.isCanonical(encoded_id); // $ExpectType boolean\nUuid.isRaw(encoded_id); // $ExpectType boolean\nUuid.name; // $ExpectType string\nUuid.type; // $ExpectType ConstructorOf<Uuid>\nUuid.toCanonical(uuid); // $ExpectType string\nUuid.toCanonical(uuid_1); // $ExpectType string\nUuid.toCanonical(uuid_4); // $ExpectType string\nUuid.toCanonical(uuid_6); // $ExpectType string\nUuid.toCanonical(uuid_nil); // $ExpectType string\nUuid.toRaw(uuid); // $ExpectType string\nUuid.toRaw(uuid_1); // $ExpectType string\nUuid.toRaw(uuid_4); // $ExpectType string\nUuid.toRaw(uuid_6); // $ExpectType string\nUuid.toRaw(uuid_nil); // $ExpectType string\nUuid.versioned_ids; // $ExpectType IdFactory<Uuid>[]\n\nUuid1.MAX(); // $ExpectType Uuid1\nUuid1.MIN(); // $ExpectType Uuid1\nUuid1.construct(bytes); // $ExpectType Uuid1\nUuid1.fromCanonical(encoded_id); // $ExpectType Uuid1\nUuid1.fromCanonicalTrusted(encoded_id); // $ExpectType Uuid1\nUuid1.fromRaw(encoded_id); // $ExpectType Uuid1\nUuid1.fromRawTrusted(encoded_id); // $ExpectType Uuid1\nUuid1.generate(); // $ExpectType Uuid1\nUuid1.generate({ node, time: now }); // $ExpectType Uuid1\nUuid1.generate({}); // $ExpectType Uuid1\nUuid1.isCanonical(encoded_id); // $ExpectType boolean\nUuid1.isRaw(encoded_id); // $ExpectType boolean\nUuid1.name; // $ExpectType string\nUuid1.type; // $ExpectType ConstructorOf<Uuid1>\nUuid1.toCanonical(uuid_1); // $ExpectType string\nUuid1.toRaw(uuid_1); // $ExpectType string\n\nUuid4.MAX(); // $ExpectType Uuid4\nUuid4.MIN(); // $ExpectType Uuid4\nUuid4.construct(bytes); // $ExpectType Uuid4\nUuid4.fromCanonical(encoded_id); // $ExpectType Uuid4\nUuid4.fromCanonicalTrusted(encoded_id); // $ExpectType Uuid4\nUuid4.fromRaw(encoded_id); // $ExpectType Uuid4\nUuid4.fromRawTrusted(encoded_id); // $ExpectType Uuid4\nUuid4.generate(); // $ExpectType Uuid4\nUuid4.generate({}); // $ExpectType Uuid4\nUuid4.isCanonical(encoded_id); // $ExpectType boolean\nUuid4.isRaw(encoded_id); // $ExpectType boolean\nUuid4.name; // $ExpectType string\nUuid4.type; // $ExpectType ConstructorOf<Uuid4>\nUuid4.toCanonical(uuid_4); // $ExpectType string\nUuid4.toRaw(uuid_4); // $ExpectType string\n\nUuid6.MAX(); // $ExpectType Uuid6\nUuid6.MIN(); // $ExpectType Uuid6\nUuid6.construct(bytes); // $ExpectType Uuid6\nUuid6.fromCanonical(encoded_id); // $ExpectType Uuid6\nUuid6.fromCanonicalTrusted(encoded_id); // $ExpectType Uuid6\nUuid6.fromRaw(encoded_id); // $ExpectType Uuid6\nUuid6.fromRawTrusted(encoded_id); // $ExpectType Uuid6\nUuid6.generate(); // $ExpectType Uuid6\nUuid6.generate({ node, time: now }); // $ExpectType Uuid6\nUuid6.generate({}); // $ExpectType Uuid6\nUuid6.isCanonical(encoded_id); // $ExpectType boolean\nUuid6.isRaw(encoded_id); // $ExpectType boolean\nUuid6.name; // $ExpectType string\nUuid6.type; // $ExpectType ConstructorOf<Uuid6>\nUuid6.toCanonical(uuid_6); // $ExpectType string\nUuid6.toRaw(uuid_6); // $ExpectType string\n\nUuidNil.MAX(); // $ExpectType UuidNil\nUuidNil.MIN(); // $ExpectType UuidNil\nUuidNil.construct(bytes); // $ExpectType UuidNil\nUuidNil.fromCanonical(encoded_id); // $ExpectType UuidNil\nUuidNil.fromCanonicalTrusted(encoded_id); // $ExpectType UuidNil\nUuidNil.fromRaw(encoded_id); // $ExpectType UuidNil\nUuidNil.fromRawTrusted(encoded_id); // $ExpectType UuidNil\nUuidNil.generate(); // $ExpectType UuidNil\nUuidNil.generate({}); // $ExpectType UuidNil\nUuidNil.isCanonical(encoded_id); // $ExpectType boolean\nUuidNil.isRaw(encoded_id); // $ExpectType boolean\nUuidNil.name; // $ExpectType string\nUuidNil.type; // $ExpectType ConstructorOf<UuidNil>\nUuidNil.toCanonical(uuid_nil); // $ExpectType string\nUuidNil.toRaw(uuid_nil); // $ExpectType string\n\nulid + ''; // $ExpectType string\nulid.bytes; // $ExpectType Uint8Array\nulid.clone(); // $ExpectType Ulid\nulid.compare(ulid); // $ExpectType number\nulid.equal(ulid); // $ExpectType boolean\nulid.time; // $ExpectType Date\nulid.toCanonical(); // $ExpectType string\nulid.toRaw(); // $ExpectType string\nulid instanceof Ulid.type; // $ExpectType boolean\n\nulid_monotonic + ''; // $ExpectType string\nulid_monotonic.bytes; // $ExpectType Uint8Array\nulid_monotonic.clone(); // $ExpectType UlidMonotonic\nulid_monotonic.compare(ulid_monotonic); // $ExpectType number\nulid_monotonic.equal(ulid_monotonic); // $ExpectType boolean\nulid_monotonic.time; // $ExpectType Date\nulid_monotonic.toCanonical(); // $ExpectType string\nulid_monotonic.toRaw(); // $ExpectType string\nulid_monotonic instanceof UlidMonotonic.type; // $ExpectType boolean\n\nuuid_1 + ''; // $ExpectType string\nuuid_1.bytes; // $ExpectType Uint8Array\nuuid_1.clock_sequence; // $ExpectType number\nuuid_1.clone(); // $ExpectType Uuid1\nuuid_1.compare(uuid_1); // $ExpectType number\nuuid_1.equal(uuid_1); // $ExpectType boolean\nuuid_1.hires_time; // $ExpectType number\nuuid_1.node; // $ExpectType Uint8Array\nuuid_1.time; // $ExpectType Date\nuuid_1.toCanonical(); // $ExpectType string\nuuid_1.toRaw(); // $ExpectType string\nuuid_1.variant; // $ExpectType number\nuuid_1.version; // $ExpectType number\nuuid_1 instanceof Uuid1.type; // $ExpectType boolean\n\nuuid_4 + ''; // $ExpectType string\nuuid_4.bytes; // $ExpectType Uint8Array\nuuid_4.clone(); // $ExpectType Uuid4\nuuid_4.compare(uuid_4); // $ExpectType number\nuuid_4.equal(uuid_4); // $ExpectType boolean\nuuid_4.toCanonical(); // $ExpectType string\nuuid_4.toRaw(); // $ExpectType string\nuuid_4.variant; // $ExpectType number\nuuid_4.version; // $ExpectType number\nuuid_4 instanceof Uuid4.type; // $ExpectType boolean\n\nuuid_6 + ''; // $ExpectType string\nuuid_6.bytes; // $ExpectType Uint8Array\nuuid_6.clock_sequence; // $ExpectType number\nuuid_6.clone(); // $ExpectType Uuid6\nuuid_6.compare(uuid_6); // $ExpectType number\nuuid_6.equal(uuid_6); // $ExpectType boolean\nuuid_6.hires_time; // $ExpectType number\nuuid_6.node; // $ExpectType Uint8Array\nuuid_6.time; // $ExpectType Date\nuuid_6.toCanonical(); // $ExpectType string\nuuid_6.toRaw(); // $ExpectType string\nuuid_6.variant; // $ExpectType number\nuuid_6.version; // $ExpectType number\nuuid_6 instanceof Uuid6.type; // $ExpectType boolean\n\nuuid_nil + ''; // $ExpectType string\nuuid_nil.bytes; // $ExpectType Uint8Array\nuuid_nil.clone(); // $ExpectType UuidNil\nuuid_nil.compare(uuid_nil); // $ExpectType number\nuuid_nil.equal(uuid_nil); // $ExpectType boolean\nuuid_nil.toCanonical(); // $ExpectType string\nuuid_nil.toRaw(); // $ExpectType string\nuuid_nil.variant; // $ExpectType number\nuuid_nil.version; // $ExpectType number\nuuid_nil instanceof UuidNil.type; // $ExpectType boolean\n\nidCompare(ulid, uuid_nil); // $expectType number\nidEqual(ulid, uuid_nil); // $expectType boolean\n\nnew Error() instanceof Exception.Id128Error; // $ExpectType boolean\nnew Error() instanceof Exception.ClockSequenceOverflow; // $ExpectType boolean\nnew Error() instanceof Exception.InvalidBytes; // $ExpectType boolean\nnew Error() instanceof Exception.InvalidEncoding; // $ExpectType boolean\nnew Error() instanceof Exception.InvalidEpoch; // $ExpectType boolean\nnew Error() instanceof Exception.UnsupportedVersion; // $ExpectType boolean\n"
  },
  {
    "path": "types/tsconfig.json",
    "content": "{\n\t\"compilerOptions\": {\n\t\t\"lib\": [\"es6\"],\n\t\t\"module\": \"commonjs\",\n\t\t\"noEmit\": true,\n\t\t\"noImplicitAny\": true,\n\t\t\"noImplicitThis\": true,\n\t\t\"strictBindCallApply\": true,\n\t\t\"strictFunctionTypes\": true,\n\t\t\"strictNullChecks\": true,\n\t\t\"baseUrl\": \".\",\n\t\t\"paths\": { \"id128\": [\".\"] }\n\t}\n}\n"
  },
  {
    "path": "types/tslint.json",
    "content": "{\n\t\"extends\": \"dtslint/dtslint.json\",\n\t\"rules\": {\n\t\t\"indent\": [true, \"tabs\", 2],\n\t\t\"no-empty-interface\": false\n\t}\n}\n"
  },
  {
    "path": "utils.js",
    "content": "const { Ulid } = require('./src/id/ulid');\nconst { UlidMonotonic } = require('./src/id/ulid-monotonic');\nconst { Uuid } = require('./src/id/uuid');\nconst { Uuid1 } = require('./src/id/uuid-1');\nconst { Uuid4 } = require('./src/id/uuid-4');\nconst { Uuid6 } = require('./src/id/uuid-6');\nconst { UuidNil } = require('./src/id/uuid-nil');\n\nconst Crockford32Coder = require('./src/coder/crockford32');\nconst HexCoder = require('./src/coder/hex');\nconst UuidCoder = require('./src/coder/uuid');\n\nconst { IdFactory } = require('./src/factory/id');\nconst { VersionedIdFactory } = require('./src/factory/versioned-id');\nconst Exception = require('./src/common/exception');\n\nmodule.exports = {\n\tCoder: {\n\t\tCrockford32: Crockford32Coder,\n\t\tHex: HexCoder,\n\t\tUuid: UuidCoder,\n\t},\n\tException,\n\tId: {\n\t\tUlid,\n\t\tUlidMonotonic,\n\t\tUuid,\n\t\tUuid1,\n\t\tUuid4,\n\t\tUuid6,\n\t\tUuidNil,\n\t},\n\tIdFactory,\n\tVersionedIdFactory,\n};\n"
  }
]