semola 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -29
- package/dist/api/core/index.cjs +206 -0
- package/dist/api/core/index.d.cts +21 -0
- package/dist/api/core/index.d.cts.map +1 -0
- package/dist/api/core/index.d.mts +21 -0
- package/dist/api/core/index.d.mts.map +1 -0
- package/dist/api/core/index.mjs +208 -0
- package/dist/api/core/index.mjs.map +1 -0
- package/dist/api/core/types.d.cts +107 -0
- package/dist/api/core/types.d.cts.map +1 -0
- package/dist/api/core/types.d.mts +107 -0
- package/dist/api/core/types.d.mts.map +1 -0
- package/dist/api/middleware/index.cjs +8 -0
- package/dist/api/middleware/index.d.cts +11 -0
- package/dist/api/middleware/index.d.cts.map +1 -0
- package/dist/api/middleware/index.d.mts +11 -0
- package/dist/api/middleware/index.d.mts.map +1 -0
- package/dist/api/middleware/index.mjs +10 -0
- package/dist/api/middleware/index.mjs.map +1 -0
- package/dist/api/middleware/types.d.cts +16 -0
- package/dist/api/middleware/types.d.cts.map +1 -0
- package/dist/api/middleware/types.d.mts +16 -0
- package/dist/api/middleware/types.d.mts.map +1 -0
- package/dist/api/openapi/index.cjs +254 -0
- package/dist/api/openapi/index.mjs +256 -0
- package/dist/api/openapi/index.mjs.map +1 -0
- package/dist/api/openapi/types.d.cts +60 -0
- package/dist/api/openapi/types.d.cts.map +1 -0
- package/dist/api/openapi/types.d.mts +60 -0
- package/dist/api/openapi/types.d.mts.map +1 -0
- package/dist/api/validation/index.cjs +64 -0
- package/dist/api/validation/index.mjs +61 -0
- package/dist/api/validation/index.mjs.map +1 -0
- package/dist/cache/types.d.cts +17 -0
- package/dist/cache/types.d.cts.map +1 -0
- package/dist/cache/types.d.mts +17 -0
- package/dist/cache/types.d.mts.map +1 -0
- package/dist/cron/builder/index.cjs +166 -0
- package/dist/cron/builder/index.d.cts +28 -0
- package/dist/cron/builder/index.d.cts.map +1 -0
- package/dist/cron/builder/index.d.mts +28 -0
- package/dist/cron/builder/index.d.mts.map +1 -0
- package/dist/cron/builder/index.mjs +163 -0
- package/dist/cron/builder/index.mjs.map +1 -0
- package/dist/cron/builder/types.cjs +27 -0
- package/dist/cron/builder/types.d.cts +79 -0
- package/dist/cron/builder/types.d.cts.map +1 -0
- package/dist/cron/builder/types.d.mts +79 -0
- package/dist/cron/builder/types.d.mts.map +1 -0
- package/dist/cron/builder/types.mjs +28 -0
- package/dist/cron/builder/types.mjs.map +1 -0
- package/dist/cron/core/index.cjs +308 -0
- package/dist/cron/core/index.d.cts +39 -0
- package/dist/cron/core/index.d.cts.map +1 -0
- package/dist/cron/core/index.d.mts +39 -0
- package/dist/cron/core/index.d.mts.map +1 -0
- package/dist/cron/core/index.mjs +310 -0
- package/dist/cron/core/index.mjs.map +1 -0
- package/dist/cron/core/scanner.cjs +237 -0
- package/dist/cron/core/scanner.mjs +238 -0
- package/dist/cron/core/scanner.mjs.map +1 -0
- package/dist/cron/core/types.d.cts +11 -0
- package/dist/cron/core/types.d.cts.map +1 -0
- package/dist/cron/core/types.d.mts +11 -0
- package/dist/cron/core/types.d.mts.map +1 -0
- package/dist/errors/types.d.cts +5 -0
- package/dist/errors/types.d.cts.map +1 -0
- package/dist/errors/types.d.mts +5 -0
- package/dist/errors/types.d.mts.map +1 -0
- package/dist/i18n/types.d.cts +13 -0
- package/dist/i18n/types.d.cts.map +1 -0
- package/dist/i18n/types.d.mts +13 -0
- package/dist/i18n/types.d.mts.map +1 -0
- package/dist/lib/api/index.cjs +5 -0
- package/dist/lib/api/index.d.cts +5 -0
- package/dist/lib/api/index.d.mts +5 -0
- package/dist/lib/api/index.mjs +3 -0
- package/dist/lib/cache/index.cjs +74 -0
- package/dist/lib/cache/index.d.cts +36 -0
- package/dist/lib/cache/index.d.cts.map +1 -0
- package/dist/lib/cache/index.d.mts +36 -0
- package/dist/lib/cache/index.d.mts.map +1 -0
- package/dist/lib/cache/index.mjs +75 -0
- package/dist/lib/cache/index.mjs.map +1 -0
- package/dist/lib/cron/index.cjs +13 -0
- package/dist/lib/cron/index.d.cts +4 -0
- package/dist/lib/cron/index.d.mts +4 -0
- package/dist/lib/cron/index.mjs +4 -0
- package/dist/lib/errors/index.cjs +30 -0
- package/dist/lib/errors/index.d.cts +13 -0
- package/dist/lib/errors/index.d.cts.map +1 -0
- package/dist/lib/errors/index.d.mts +13 -0
- package/dist/lib/errors/index.d.mts.map +1 -0
- package/dist/lib/errors/index.mjs +28 -0
- package/dist/lib/errors/index.mjs.map +1 -0
- package/dist/lib/i18n/index.cjs +42 -0
- package/dist/lib/i18n/index.d.cts +20 -0
- package/dist/lib/i18n/index.d.cts.map +1 -0
- package/dist/lib/i18n/index.d.mts +20 -0
- package/dist/lib/i18n/index.d.mts.map +1 -0
- package/dist/lib/i18n/index.mjs +43 -0
- package/dist/lib/i18n/index.mjs.map +1 -0
- package/dist/lib/logging/index.cjs +18 -0
- package/dist/lib/logging/index.d.cts +7 -0
- package/dist/lib/logging/index.d.mts +7 -0
- package/dist/lib/logging/index.mjs +5 -0
- package/dist/lib/orm/index.cjs +20 -0
- package/dist/lib/orm/index.d.cts +7 -0
- package/dist/lib/orm/index.d.mts +7 -0
- package/dist/lib/orm/index.mjs +6 -0
- package/dist/lib/policy/index.cjs +99 -0
- package/dist/lib/policy/index.d.cts +21 -0
- package/dist/lib/policy/index.d.cts.map +1 -0
- package/dist/lib/policy/index.d.mts +21 -0
- package/dist/lib/policy/index.d.mts.map +1 -0
- package/dist/lib/policy/index.mjs +81 -0
- package/dist/lib/policy/index.mjs.map +1 -0
- package/dist/lib/prompts/index.cjs +409 -0
- package/dist/lib/prompts/index.d.cts +31 -0
- package/dist/lib/prompts/index.d.cts.map +1 -0
- package/dist/lib/prompts/index.d.mts +31 -0
- package/dist/lib/prompts/index.d.mts.map +1 -0
- package/dist/lib/prompts/index.mjs +405 -0
- package/dist/lib/prompts/index.mjs.map +1 -0
- package/dist/lib/pubsub/index.cjs +117 -0
- package/dist/lib/pubsub/index.d.cts +36 -0
- package/dist/lib/pubsub/index.d.cts.map +1 -0
- package/dist/lib/pubsub/index.d.mts +36 -0
- package/dist/lib/pubsub/index.d.mts.map +1 -0
- package/dist/lib/pubsub/index.mjs +118 -0
- package/dist/lib/pubsub/index.mjs.map +1 -0
- package/dist/lib/queue/index.cjs +182 -0
- package/dist/lib/queue/index.d.cts +32 -0
- package/dist/lib/queue/index.d.cts.map +1 -0
- package/dist/lib/queue/index.d.mts +32 -0
- package/dist/lib/queue/index.d.mts.map +1 -0
- package/dist/lib/queue/index.mjs +183 -0
- package/dist/lib/queue/index.mjs.map +1 -0
- package/dist/lib/workflow/index.cjs +534 -0
- package/dist/lib/workflow/index.d.cts +7 -0
- package/dist/lib/workflow/index.d.cts.map +1 -0
- package/dist/lib/workflow/index.d.mts +7 -0
- package/dist/lib/workflow/index.d.mts.map +1 -0
- package/dist/lib/workflow/index.mjs +535 -0
- package/dist/lib/workflow/index.mjs.map +1 -0
- package/dist/logging/core/index.cjs +99 -0
- package/dist/logging/core/index.d.cts +26 -0
- package/dist/logging/core/index.d.cts.map +1 -0
- package/dist/logging/core/index.d.mts +26 -0
- package/dist/logging/core/index.d.mts.map +1 -0
- package/dist/logging/core/index.mjs +99 -0
- package/dist/logging/core/index.mjs.map +1 -0
- package/dist/logging/core/types.cjs +10 -0
- package/dist/logging/core/types.d.cts +22 -0
- package/dist/logging/core/types.d.cts.map +1 -0
- package/dist/logging/core/types.d.mts +22 -0
- package/dist/logging/core/types.d.mts.map +1 -0
- package/dist/logging/core/types.mjs +12 -0
- package/dist/logging/core/types.mjs.map +1 -0
- package/dist/logging/formatter/index.cjs +119 -0
- package/dist/logging/formatter/index.d.cts +27 -0
- package/dist/logging/formatter/index.d.cts.map +1 -0
- package/dist/logging/formatter/index.d.mts +27 -0
- package/dist/logging/formatter/index.d.mts.map +1 -0
- package/dist/logging/formatter/index.mjs +115 -0
- package/dist/logging/formatter/index.mjs.map +1 -0
- package/dist/logging/formatter/types.d.cts +5 -0
- package/dist/logging/formatter/types.d.cts.map +1 -0
- package/dist/logging/formatter/types.d.mts +5 -0
- package/dist/logging/formatter/types.d.mts.map +1 -0
- package/dist/logging/provider/index.cjs +165 -0
- package/dist/logging/provider/index.d.cts +28 -0
- package/dist/logging/provider/index.d.cts.map +1 -0
- package/dist/logging/provider/index.d.mts +28 -0
- package/dist/logging/provider/index.d.mts.map +1 -0
- package/dist/logging/provider/index.mjs +165 -0
- package/dist/logging/provider/index.mjs.map +1 -0
- package/dist/logging/provider/types.d.cts +23 -0
- package/dist/logging/provider/types.d.cts.map +1 -0
- package/dist/logging/provider/types.d.mts +23 -0
- package/dist/logging/provider/types.d.mts.map +1 -0
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +80 -0
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +1 -0
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +80 -0
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +1 -0
- package/dist/orm/column.cjs +137 -0
- package/dist/orm/column.d.cts +121 -0
- package/dist/orm/column.d.cts.map +1 -0
- package/dist/orm/column.d.mts +121 -0
- package/dist/orm/column.d.mts.map +1 -0
- package/dist/orm/column.mjs +132 -0
- package/dist/orm/column.mjs.map +1 -0
- package/dist/orm/dialect/index.cjs +14 -0
- package/dist/orm/dialect/index.mjs +16 -0
- package/dist/orm/dialect/index.mjs.map +1 -0
- package/dist/orm/dialect/mysql.cjs +31 -0
- package/dist/orm/dialect/mysql.mjs +33 -0
- package/dist/orm/dialect/mysql.mjs.map +1 -0
- package/dist/orm/dialect/postgres.cjs +23 -0
- package/dist/orm/dialect/postgres.mjs +25 -0
- package/dist/orm/dialect/postgres.mjs.map +1 -0
- package/dist/orm/dialect/sqlite.cjs +31 -0
- package/dist/orm/dialect/sqlite.mjs +33 -0
- package/dist/orm/dialect/sqlite.mjs.map +1 -0
- package/dist/orm/dialect/utils.cjs +8 -0
- package/dist/orm/dialect/utils.mjs +10 -0
- package/dist/orm/dialect/utils.mjs.map +1 -0
- package/dist/orm/internal/table-columns.cjs +31 -0
- package/dist/orm/internal/table-columns.mjs +32 -0
- package/dist/orm/internal/table-columns.mjs.map +1 -0
- package/dist/orm/internal/table-lookup.cjs +35 -0
- package/dist/orm/internal/table-lookup.mjs +35 -0
- package/dist/orm/internal/table-lookup.mjs.map +1 -0
- package/dist/orm/internal/table-relations.cjs +28 -0
- package/dist/orm/internal/table-relations.mjs +29 -0
- package/dist/orm/internal/table-relations.mjs.map +1 -0
- package/dist/orm/migration/config.cjs +7 -0
- package/dist/orm/migration/config.d.cts +7 -0
- package/dist/orm/migration/config.d.cts.map +1 -0
- package/dist/orm/migration/config.d.mts +7 -0
- package/dist/orm/migration/config.d.mts.map +1 -0
- package/dist/orm/migration/config.mjs +8 -0
- package/dist/orm/migration/config.mjs.map +1 -0
- package/dist/orm/migration/types.d.cts +20 -0
- package/dist/orm/migration/types.d.cts.map +1 -0
- package/dist/orm/migration/types.d.mts +20 -0
- package/dist/orm/migration/types.d.mts.map +1 -0
- package/dist/orm/orm.cjs +41 -0
- package/dist/orm/orm.d.cts +18 -0
- package/dist/orm/orm.d.cts.map +1 -0
- package/dist/orm/orm.d.mts +18 -0
- package/dist/orm/orm.d.mts.map +1 -0
- package/dist/orm/orm.mjs +43 -0
- package/dist/orm/orm.mjs.map +1 -0
- package/dist/orm/relation.cjs +18 -0
- package/dist/orm/relation.d.cts +8 -0
- package/dist/orm/relation.d.cts.map +1 -0
- package/dist/orm/relation.d.mts +8 -0
- package/dist/orm/relation.d.mts.map +1 -0
- package/dist/orm/relation.mjs +19 -0
- package/dist/orm/relation.mjs.map +1 -0
- package/dist/orm/runtime/builders/mutations.cjs +29 -0
- package/dist/orm/runtime/builders/mutations.mjs +28 -0
- package/dist/orm/runtime/builders/mutations.mjs.map +1 -0
- package/dist/orm/runtime/builders/select.cjs +18 -0
- package/dist/orm/runtime/builders/select.mjs +19 -0
- package/dist/orm/runtime/builders/select.mjs.map +1 -0
- package/dist/orm/runtime/client.cjs +90 -0
- package/dist/orm/runtime/client.mjs +92 -0
- package/dist/orm/runtime/client.mjs.map +1 -0
- package/dist/orm/runtime/context.cjs +49 -0
- package/dist/orm/runtime/context.mjs +51 -0
- package/dist/orm/runtime/context.mjs.map +1 -0
- package/dist/orm/runtime/dialect/index.cjs +11 -0
- package/dist/orm/runtime/dialect/index.mjs +13 -0
- package/dist/orm/runtime/dialect/index.mjs.map +1 -0
- package/dist/orm/runtime/dialect/mysql.cjs +95 -0
- package/dist/orm/runtime/dialect/mysql.mjs +97 -0
- package/dist/orm/runtime/dialect/mysql.mjs.map +1 -0
- package/dist/orm/runtime/dialect/postgres.cjs +51 -0
- package/dist/orm/runtime/dialect/postgres.mjs +53 -0
- package/dist/orm/runtime/dialect/postgres.mjs.map +1 -0
- package/dist/orm/runtime/dialect/sqlite.cjs +4 -0
- package/dist/orm/runtime/dialect/sqlite.mjs +7 -0
- package/dist/orm/runtime/dialect/sqlite.mjs.map +1 -0
- package/dist/orm/runtime/errors.cjs +19 -0
- package/dist/orm/runtime/errors.mjs +21 -0
- package/dist/orm/runtime/errors.mjs.map +1 -0
- package/dist/orm/runtime/hydrate/many.cjs +46 -0
- package/dist/orm/runtime/hydrate/many.mjs +48 -0
- package/dist/orm/runtime/hydrate/many.mjs.map +1 -0
- package/dist/orm/runtime/hydrate/one.cjs +38 -0
- package/dist/orm/runtime/hydrate/one.mjs +40 -0
- package/dist/orm/runtime/hydrate/one.mjs.map +1 -0
- package/dist/orm/runtime/hydrate.cjs +49 -0
- package/dist/orm/runtime/hydrate.mjs +51 -0
- package/dist/orm/runtime/hydrate.mjs.map +1 -0
- package/dist/orm/runtime/rows.cjs +30 -0
- package/dist/orm/runtime/rows.mjs +31 -0
- package/dist/orm/runtime/rows.mjs.map +1 -0
- package/dist/orm/runtime/utils.cjs +27 -0
- package/dist/orm/runtime/utils.mjs +27 -0
- package/dist/orm/runtime/utils.mjs.map +1 -0
- package/dist/orm/sql/parse-array.cjs +64 -0
- package/dist/orm/sql/parse-array.mjs +66 -0
- package/dist/orm/sql/parse-array.mjs.map +1 -0
- package/dist/orm/sql/plan/select.cjs +36 -0
- package/dist/orm/sql/plan/select.mjs +38 -0
- package/dist/orm/sql/plan/select.mjs.map +1 -0
- package/dist/orm/sql/plan/where/operators.cjs +95 -0
- package/dist/orm/sql/plan/where/operators.mjs +97 -0
- package/dist/orm/sql/plan/where/operators.mjs.map +1 -0
- package/dist/orm/sql/plan/where.cjs +59 -0
- package/dist/orm/sql/plan/where.mjs +61 -0
- package/dist/orm/sql/plan/where.mjs.map +1 -0
- package/dist/orm/sql/serialize/clauses.cjs +36 -0
- package/dist/orm/sql/serialize/clauses.mjs +37 -0
- package/dist/orm/sql/serialize/clauses.mjs.map +1 -0
- package/dist/orm/sql/serialize/joins.cjs +31 -0
- package/dist/orm/sql/serialize/joins.mjs +33 -0
- package/dist/orm/sql/serialize/joins.mjs.map +1 -0
- package/dist/orm/sql/serialize/values.cjs +30 -0
- package/dist/orm/sql/serialize/values.mjs +32 -0
- package/dist/orm/sql/serialize/values.mjs.map +1 -0
- package/dist/orm/sql/serialize/where/predicate.cjs +73 -0
- package/dist/orm/sql/serialize/where/predicate.mjs +75 -0
- package/dist/orm/sql/serialize/where/predicate.mjs.map +1 -0
- package/dist/orm/sql/serialize/where/tree.cjs +26 -0
- package/dist/orm/sql/serialize/where/tree.mjs +28 -0
- package/dist/orm/sql/serialize/where/tree.mjs.map +1 -0
- package/dist/orm/sql/serialize/where.cjs +10 -0
- package/dist/orm/sql/serialize/where.mjs +12 -0
- package/dist/orm/sql/serialize/where.mjs.map +1 -0
- package/dist/orm/sql/serialize.cjs +24 -0
- package/dist/orm/sql/serialize.mjs +25 -0
- package/dist/orm/sql/serialize.mjs.map +1 -0
- package/dist/orm/table.cjs +12 -0
- package/dist/orm/table.d.cts +12 -0
- package/dist/orm/table.d.cts.map +1 -0
- package/dist/orm/table.d.mts +12 -0
- package/dist/orm/table.d.mts.map +1 -0
- package/dist/orm/table.mjs +14 -0
- package/dist/orm/table.mjs.map +1 -0
- package/dist/orm/types.d.cts +183 -0
- package/dist/orm/types.d.cts.map +1 -0
- package/dist/orm/types.d.mts +183 -0
- package/dist/orm/types.d.mts.map +1 -0
- package/dist/policy/helpers.cjs +206 -0
- package/dist/policy/helpers.d.cts +50 -0
- package/dist/policy/helpers.d.cts.map +1 -0
- package/dist/policy/helpers.d.mts +50 -0
- package/dist/policy/helpers.d.mts.map +1 -0
- package/dist/policy/helpers.mjs +190 -0
- package/dist/policy/helpers.mjs.map +1 -0
- package/dist/policy/types.d.cts +16 -0
- package/dist/policy/types.d.cts.map +1 -0
- package/dist/policy/types.d.mts +16 -0
- package/dist/policy/types.d.mts.map +1 -0
- package/dist/prompts/core/keys.cjs +165 -0
- package/dist/prompts/core/keys.mjs +167 -0
- package/dist/prompts/core/keys.mjs.map +1 -0
- package/dist/prompts/core/runtime.cjs +104 -0
- package/dist/prompts/core/runtime.mjs +106 -0
- package/dist/prompts/core/runtime.mjs.map +1 -0
- package/dist/prompts/core/session.cjs +98 -0
- package/dist/prompts/core/session.mjs +100 -0
- package/dist/prompts/core/session.mjs.map +1 -0
- package/dist/prompts/core/types.d.cts +21 -0
- package/dist/prompts/core/types.d.cts.map +1 -0
- package/dist/prompts/core/types.d.mts +21 -0
- package/dist/prompts/core/types.d.mts.map +1 -0
- package/dist/prompts/types.d.cts +52 -0
- package/dist/prompts/types.d.cts.map +1 -0
- package/dist/prompts/types.d.mts +52 -0
- package/dist/prompts/types.d.mts.map +1 -0
- package/dist/pubsub/types.d.cts +10 -0
- package/dist/pubsub/types.d.cts.map +1 -0
- package/dist/pubsub/types.d.mts +10 -0
- package/dist/pubsub/types.d.mts.map +1 -0
- package/dist/queue/types.d.cts +47 -0
- package/dist/queue/types.d.cts.map +1 -0
- package/dist/queue/types.d.mts +47 -0
- package/dist/queue/types.d.mts.map +1 -0
- package/dist/workflow/types.d.cts +83 -0
- package/dist/workflow/types.d.cts.map +1 -0
- package/dist/workflow/types.d.mts +83 -0
- package/dist/workflow/types.d.mts.map +1 -0
- package/package.json +112 -16
- package/dist/lib/api/core/index.d.ts +0 -15
- package/dist/lib/api/core/index.d.ts.map +0 -1
- package/dist/lib/api/core/index.js +0 -218
- package/dist/lib/api/core/index.js.map +0 -1
- package/dist/lib/api/core/index.test.d.ts +0 -2
- package/dist/lib/api/core/index.test.d.ts.map +0 -1
- package/dist/lib/api/core/index.test.js +0 -219
- package/dist/lib/api/core/index.test.js.map +0 -1
- package/dist/lib/api/core/types.d.ts +0 -109
- package/dist/lib/api/core/types.d.ts.map +0 -1
- package/dist/lib/api/core/types.js +0 -2
- package/dist/lib/api/core/types.js.map +0 -1
- package/dist/lib/api/index.d.ts +0 -5
- package/dist/lib/api/index.d.ts.map +0 -1
- package/dist/lib/api/index.js +0 -3
- package/dist/lib/api/index.js.map +0 -1
- package/dist/lib/api/middleware/index.d.ts +0 -7
- package/dist/lib/api/middleware/index.d.ts.map +0 -1
- package/dist/lib/api/middleware/index.js +0 -7
- package/dist/lib/api/middleware/index.js.map +0 -1
- package/dist/lib/api/middleware/index.test.d.ts +0 -2
- package/dist/lib/api/middleware/index.test.d.ts.map +0 -1
- package/dist/lib/api/middleware/index.test.js +0 -67
- package/dist/lib/api/middleware/index.test.js.map +0 -1
- package/dist/lib/api/middleware/types.d.ts +0 -12
- package/dist/lib/api/middleware/types.d.ts.map +0 -1
- package/dist/lib/api/middleware/types.js +0 -2
- package/dist/lib/api/middleware/types.js.map +0 -1
- package/dist/lib/api/openapi/index.d.ts +0 -31
- package/dist/lib/api/openapi/index.d.ts.map +0 -1
- package/dist/lib/api/openapi/index.js +0 -284
- package/dist/lib/api/openapi/index.js.map +0 -1
- package/dist/lib/api/openapi/index.test.d.ts +0 -2
- package/dist/lib/api/openapi/index.test.d.ts.map +0 -1
- package/dist/lib/api/openapi/index.test.js +0 -359
- package/dist/lib/api/openapi/index.test.js.map +0 -1
- package/dist/lib/api/openapi/types.d.ts +0 -57
- package/dist/lib/api/openapi/types.d.ts.map +0 -1
- package/dist/lib/api/openapi/types.js +0 -5
- package/dist/lib/api/openapi/types.js.map +0 -1
- package/dist/lib/api/validation/index.d.ts +0 -33
- package/dist/lib/api/validation/index.d.ts.map +0 -1
- package/dist/lib/api/validation/index.js +0 -92
- package/dist/lib/api/validation/index.js.map +0 -1
- package/dist/lib/api/validation/index.test.d.ts +0 -2
- package/dist/lib/api/validation/index.test.d.ts.map +0 -1
- package/dist/lib/api/validation/index.test.js +0 -135
- package/dist/lib/api/validation/index.test.js.map +0 -1
- package/dist/lib/cache/index.d.ts +0 -25
- package/dist/lib/cache/index.d.ts.map +0 -1
- package/dist/lib/cache/index.js +0 -62
- package/dist/lib/cache/index.js.map +0 -1
- package/dist/lib/cache/index.test.d.ts +0 -2
- package/dist/lib/cache/index.test.d.ts.map +0 -1
- package/dist/lib/cache/index.test.js +0 -314
- package/dist/lib/cache/index.test.js.map +0 -1
- package/dist/lib/cache/types.d.ts +0 -5
- package/dist/lib/cache/types.d.ts.map +0 -1
- package/dist/lib/cache/types.js +0 -2
- package/dist/lib/cache/types.js.map +0 -1
- package/dist/lib/errors/index.d.ts +0 -9
- package/dist/lib/errors/index.d.ts.map +0 -1
- package/dist/lib/errors/index.js +0 -25
- package/dist/lib/errors/index.js.map +0 -1
- package/dist/lib/errors/index.test.d.ts +0 -2
- package/dist/lib/errors/index.test.d.ts.map +0 -1
- package/dist/lib/errors/index.test.js +0 -197
- package/dist/lib/errors/index.test.js.map +0 -1
- package/dist/lib/errors/types.d.ts +0 -2
- package/dist/lib/errors/types.d.ts.map +0 -1
- package/dist/lib/errors/types.js +0 -2
- package/dist/lib/errors/types.js.map +0 -1
- package/dist/lib/i18n/index.d.ts +0 -18
- package/dist/lib/i18n/index.d.ts.map +0 -1
- package/dist/lib/i18n/index.js +0 -38
- package/dist/lib/i18n/index.js.map +0 -1
- package/dist/lib/i18n/index.test.d.ts +0 -2
- package/dist/lib/i18n/index.test.d.ts.map +0 -1
- package/dist/lib/i18n/index.test.js +0 -402
- package/dist/lib/i18n/index.test.js.map +0 -1
- package/dist/lib/i18n/types.d.ts +0 -15
- package/dist/lib/i18n/types.d.ts.map +0 -1
- package/dist/lib/i18n/types.js +0 -2
- package/dist/lib/i18n/types.js.map +0 -1
- package/dist/lib/policy/index.d.ts +0 -9
- package/dist/lib/policy/index.d.ts.map +0 -1
- package/dist/lib/policy/index.js +0 -51
- package/dist/lib/policy/index.js.map +0 -1
- package/dist/lib/policy/index.test.d.ts +0 -2
- package/dist/lib/policy/index.test.d.ts.map +0 -1
- package/dist/lib/policy/index.test.js +0 -328
- package/dist/lib/policy/index.test.js.map +0 -1
- package/dist/lib/policy/types.d.ts +0 -27
- package/dist/lib/policy/types.d.ts.map +0 -1
- package/dist/lib/policy/types.js +0 -2
- package/dist/lib/policy/types.js.map +0 -1
- package/dist/lib/pubsub/index.d.ts +0 -23
- package/dist/lib/pubsub/index.d.ts.map +0 -1
- package/dist/lib/pubsub/index.js +0 -55
- package/dist/lib/pubsub/index.js.map +0 -1
- package/dist/lib/pubsub/index.test.d.ts +0 -2
- package/dist/lib/pubsub/index.test.d.ts.map +0 -1
- package/dist/lib/pubsub/index.test.js +0 -550
- package/dist/lib/pubsub/index.test.js.map +0 -1
- package/dist/lib/pubsub/types.d.ts +0 -7
- package/dist/lib/pubsub/types.d.ts.map +0 -1
- package/dist/lib/pubsub/types.js +0 -2
- package/dist/lib/pubsub/types.js.map +0 -1
- package/dist/lib/queue/index.d.ts +0 -28
- package/dist/lib/queue/index.d.ts.map +0 -1
- package/dist/lib/queue/index.js +0 -211
- package/dist/lib/queue/index.js.map +0 -1
- package/dist/lib/queue/index.test.d.ts +0 -2
- package/dist/lib/queue/index.test.d.ts.map +0 -1
- package/dist/lib/queue/index.test.js +0 -740
- package/dist/lib/queue/index.test.js.map +0 -1
- package/dist/lib/queue/types.d.ts +0 -52
- package/dist/lib/queue/types.d.ts.map +0 -1
- package/dist/lib/queue/types.js +0 -2
- package/dist/lib/queue/types.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const require_lib_errors_index = require("../../lib/errors/index.cjs");
|
|
2
|
+
//#region src/lib/api/validation/index.ts
|
|
3
|
+
const validateSchema = async (schema, data) => {
|
|
4
|
+
const result = await schema["~standard"].validate(data);
|
|
5
|
+
if (!result.issues) return require_lib_errors_index.ok(result.value);
|
|
6
|
+
return require_lib_errors_index.err("ValidationError", result.issues.map((issue) => {
|
|
7
|
+
let path = "unknown";
|
|
8
|
+
if (Array.isArray(issue.path)) path = issue.path.map(String).join(".");
|
|
9
|
+
return `${path}: ${issue.message ?? "validation failed"}`;
|
|
10
|
+
}).join(", "));
|
|
11
|
+
};
|
|
12
|
+
const validateBody = async (req, bodySchema, bodyCache) => {
|
|
13
|
+
if (!bodySchema) return require_lib_errors_index.ok(true);
|
|
14
|
+
if (!(req.headers.get("content-type") ?? "").includes("application/json")) return require_lib_errors_index.ok(void 0);
|
|
15
|
+
if (bodyCache?.parsed) return validateSchema(bodySchema, bodyCache.value);
|
|
16
|
+
const [parseError, parsedBody] = await require_lib_errors_index.mightThrow(req.json());
|
|
17
|
+
if (parseError) return require_lib_errors_index.err("ParseError", "Invalid JSON body");
|
|
18
|
+
if (bodyCache) {
|
|
19
|
+
bodyCache.parsed = true;
|
|
20
|
+
bodyCache.value = parsedBody;
|
|
21
|
+
}
|
|
22
|
+
return validateSchema(bodySchema, parsedBody);
|
|
23
|
+
};
|
|
24
|
+
const validateQuery = async (req, querySchema) => {
|
|
25
|
+
if (!querySchema) return require_lib_errors_index.ok(true);
|
|
26
|
+
const qIndex = req.url.indexOf("?");
|
|
27
|
+
if (qIndex === -1) return validateSchema(querySchema, {});
|
|
28
|
+
const hashIndex = req.url.indexOf("#", qIndex + 1);
|
|
29
|
+
const queryString = hashIndex === -1 ? req.url.slice(qIndex + 1) : req.url.slice(qIndex + 1, hashIndex);
|
|
30
|
+
const searchParams = new URLSearchParams(queryString);
|
|
31
|
+
const queryParams = {};
|
|
32
|
+
for (const key of searchParams.keys()) {
|
|
33
|
+
const values = searchParams.getAll(key);
|
|
34
|
+
const [firstValue] = values;
|
|
35
|
+
if (values.length === 1) queryParams[key] = firstValue;
|
|
36
|
+
else queryParams[key] = values;
|
|
37
|
+
}
|
|
38
|
+
return validateSchema(querySchema, queryParams);
|
|
39
|
+
};
|
|
40
|
+
const validateHeaders = async (req, headersSchema) => {
|
|
41
|
+
if (!headersSchema) return require_lib_errors_index.ok(true);
|
|
42
|
+
const headers = {};
|
|
43
|
+
req.headers.forEach((value, key) => {
|
|
44
|
+
headers[key] = value;
|
|
45
|
+
});
|
|
46
|
+
return validateSchema(headersSchema, headers);
|
|
47
|
+
};
|
|
48
|
+
const validateCookies = async (req, cookiesSchema) => {
|
|
49
|
+
if (!cookiesSchema) return require_lib_errors_index.ok(true);
|
|
50
|
+
const cookieHeader = req.headers.get("cookie") ?? "";
|
|
51
|
+
const cookieMap = new Bun.CookieMap(cookieHeader);
|
|
52
|
+
return validateSchema(cookiesSchema, Object.fromEntries(cookieMap));
|
|
53
|
+
};
|
|
54
|
+
const validateParams = async (req, paramsSchema) => {
|
|
55
|
+
if (!paramsSchema) return require_lib_errors_index.ok(true);
|
|
56
|
+
return validateSchema(paramsSchema, req.params);
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.validateBody = validateBody;
|
|
60
|
+
exports.validateCookies = validateCookies;
|
|
61
|
+
exports.validateHeaders = validateHeaders;
|
|
62
|
+
exports.validateParams = validateParams;
|
|
63
|
+
exports.validateQuery = validateQuery;
|
|
64
|
+
exports.validateSchema = validateSchema;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { err, mightThrow, ok } from "../../lib/errors/index.mjs";
|
|
2
|
+
//#region src/lib/api/validation/index.ts
|
|
3
|
+
const validateSchema = async (schema, data) => {
|
|
4
|
+
const result = await schema["~standard"].validate(data);
|
|
5
|
+
if (!result.issues) return ok(result.value);
|
|
6
|
+
return err("ValidationError", result.issues.map((issue) => {
|
|
7
|
+
let path = "unknown";
|
|
8
|
+
if (Array.isArray(issue.path)) path = issue.path.map(String).join(".");
|
|
9
|
+
return `${path}: ${issue.message ?? "validation failed"}`;
|
|
10
|
+
}).join(", "));
|
|
11
|
+
};
|
|
12
|
+
const validateBody = async (req, bodySchema, bodyCache) => {
|
|
13
|
+
if (!bodySchema) return ok(true);
|
|
14
|
+
if (!(req.headers.get("content-type") ?? "").includes("application/json")) return ok(void 0);
|
|
15
|
+
if (bodyCache?.parsed) return validateSchema(bodySchema, bodyCache.value);
|
|
16
|
+
const [parseError, parsedBody] = await mightThrow(req.json());
|
|
17
|
+
if (parseError) return err("ParseError", "Invalid JSON body");
|
|
18
|
+
if (bodyCache) {
|
|
19
|
+
bodyCache.parsed = true;
|
|
20
|
+
bodyCache.value = parsedBody;
|
|
21
|
+
}
|
|
22
|
+
return validateSchema(bodySchema, parsedBody);
|
|
23
|
+
};
|
|
24
|
+
const validateQuery = async (req, querySchema) => {
|
|
25
|
+
if (!querySchema) return ok(true);
|
|
26
|
+
const qIndex = req.url.indexOf("?");
|
|
27
|
+
if (qIndex === -1) return validateSchema(querySchema, {});
|
|
28
|
+
const hashIndex = req.url.indexOf("#", qIndex + 1);
|
|
29
|
+
const queryString = hashIndex === -1 ? req.url.slice(qIndex + 1) : req.url.slice(qIndex + 1, hashIndex);
|
|
30
|
+
const searchParams = new URLSearchParams(queryString);
|
|
31
|
+
const queryParams = {};
|
|
32
|
+
for (const key of searchParams.keys()) {
|
|
33
|
+
const values = searchParams.getAll(key);
|
|
34
|
+
const [firstValue] = values;
|
|
35
|
+
if (values.length === 1) queryParams[key] = firstValue;
|
|
36
|
+
else queryParams[key] = values;
|
|
37
|
+
}
|
|
38
|
+
return validateSchema(querySchema, queryParams);
|
|
39
|
+
};
|
|
40
|
+
const validateHeaders = async (req, headersSchema) => {
|
|
41
|
+
if (!headersSchema) return ok(true);
|
|
42
|
+
const headers = {};
|
|
43
|
+
req.headers.forEach((value, key) => {
|
|
44
|
+
headers[key] = value;
|
|
45
|
+
});
|
|
46
|
+
return validateSchema(headersSchema, headers);
|
|
47
|
+
};
|
|
48
|
+
const validateCookies = async (req, cookiesSchema) => {
|
|
49
|
+
if (!cookiesSchema) return ok(true);
|
|
50
|
+
const cookieHeader = req.headers.get("cookie") ?? "";
|
|
51
|
+
const cookieMap = new Bun.CookieMap(cookieHeader);
|
|
52
|
+
return validateSchema(cookiesSchema, Object.fromEntries(cookieMap));
|
|
53
|
+
};
|
|
54
|
+
const validateParams = async (req, paramsSchema) => {
|
|
55
|
+
if (!paramsSchema) return ok(true);
|
|
56
|
+
return validateSchema(paramsSchema, req.params);
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { validateBody, validateCookies, validateHeaders, validateParams, validateQuery, validateSchema };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/lib/api/validation/index.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { err, mightThrow, ok } from \"../../errors/index.js\";\n\nexport const validateSchema = async <T>(\n schema: StandardSchemaV1,\n data: unknown,\n) => {\n const result = await schema[\"~standard\"].validate(data);\n\n if (!result.issues) {\n return ok(result.value as T);\n }\n\n const issues = result.issues.map((issue) => {\n let path = \"unknown\";\n\n if (Array.isArray(issue.path)) {\n path = issue.path.map(String).join(\".\");\n }\n\n return `${path}: ${issue.message ?? \"validation failed\"}`;\n });\n\n const message = issues.join(\", \");\n\n return err(\"ValidationError\", message);\n};\n\nexport type BodyCache = { parsed: boolean; value: unknown };\n\n// Body cache prevents re-parsing JSON when multiple middlewares validate the same body\nexport const validateBody = async (\n req: Request,\n bodySchema?: StandardSchemaV1,\n bodyCache?: BodyCache,\n) => {\n if (!bodySchema) {\n return ok(true);\n }\n\n const contentType = req.headers.get(\"content-type\") ?? \"\";\n\n if (!contentType.includes(\"application/json\")) {\n return ok(undefined);\n }\n\n if (bodyCache?.parsed) {\n return validateSchema(bodySchema, bodyCache.value);\n }\n\n const [parseError, parsedBody] = await mightThrow(req.json());\n\n if (parseError) {\n return err(\"ParseError\", \"Invalid JSON body\");\n }\n\n if (bodyCache) {\n bodyCache.parsed = true;\n bodyCache.value = parsedBody;\n }\n\n return validateSchema(bodySchema, parsedBody);\n};\n\nexport const validateQuery = async (\n req: Request,\n querySchema?: StandardSchemaV1,\n) => {\n if (!querySchema) {\n return ok(true);\n }\n\n const qIndex = req.url.indexOf(\"?\");\n\n if (qIndex === -1) {\n return validateSchema(querySchema, {});\n }\n\n // Handle both query strings and URL fragments\n const hashIndex = req.url.indexOf(\"#\", qIndex + 1);\n const queryString =\n hashIndex === -1\n ? req.url.slice(qIndex + 1)\n : req.url.slice(qIndex + 1, hashIndex);\n\n const searchParams = new URLSearchParams(queryString);\n const queryParams: Record<string, string | string[]> = {};\n\n for (const key of searchParams.keys()) {\n const values = searchParams.getAll(key);\n const [firstValue] = values;\n\n if (values.length === 1) {\n queryParams[key] = firstValue as string;\n } else {\n queryParams[key] = values;\n }\n }\n\n return validateSchema(querySchema, queryParams);\n};\n\nexport const validateHeaders = async (\n req: Request,\n headersSchema?: StandardSchemaV1,\n) => {\n if (!headersSchema) {\n return ok(true);\n }\n\n const headers: Record<string, string> = {};\n\n req.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n return validateSchema(headersSchema, headers);\n};\n\nexport const validateCookies = async (\n req: Request,\n cookiesSchema?: StandardSchemaV1,\n) => {\n if (!cookiesSchema) {\n return ok(true);\n }\n\n // Use Bun's native CookieMap for efficient cookie parsing\n const cookieHeader = req.headers.get(\"cookie\") ?? \"\";\n const cookieMap = new Bun.CookieMap(cookieHeader);\n const cookies = Object.fromEntries(cookieMap);\n\n return validateSchema(cookiesSchema, cookies);\n};\n\nexport const validateParams = async (\n req: Bun.BunRequest,\n paramsSchema?: StandardSchemaV1,\n) => {\n if (!paramsSchema) {\n return ok(true);\n }\n\n return validateSchema(paramsSchema, req.params);\n};\n"],"mappings":";;AAGA,MAAa,iBAAiB,OAC5B,QACA,SACG;CACH,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,KAAK;AAEvD,KAAI,CAAC,OAAO,OACV,QAAO,GAAG,OAAO,MAAW;AAe9B,QAAO,IAAI,mBAZI,OAAO,OAAO,KAAK,UAAU;EAC1C,IAAI,OAAO;AAEX,MAAI,MAAM,QAAQ,MAAM,KAAK,CAC3B,QAAO,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK,IAAI;AAGzC,SAAO,GAAG,KAAK,IAAI,MAAM,WAAW;GACpC,CAEqB,KAAK,KAAK,CAEK;;AAMxC,MAAa,eAAe,OAC1B,KACA,YACA,cACG;AACH,KAAI,CAAC,WACH,QAAO,GAAG,KAAK;AAKjB,KAAI,EAFgB,IAAI,QAAQ,IAAI,eAAe,IAAI,IAEtC,SAAS,mBAAmB,CAC3C,QAAO,GAAG,KAAA,EAAU;AAGtB,KAAI,WAAW,OACb,QAAO,eAAe,YAAY,UAAU,MAAM;CAGpD,MAAM,CAAC,YAAY,cAAc,MAAM,WAAW,IAAI,MAAM,CAAC;AAE7D,KAAI,WACF,QAAO,IAAI,cAAc,oBAAoB;AAG/C,KAAI,WAAW;AACb,YAAU,SAAS;AACnB,YAAU,QAAQ;;AAGpB,QAAO,eAAe,YAAY,WAAW;;AAG/C,MAAa,gBAAgB,OAC3B,KACA,gBACG;AACH,KAAI,CAAC,YACH,QAAO,GAAG,KAAK;CAGjB,MAAM,SAAS,IAAI,IAAI,QAAQ,IAAI;AAEnC,KAAI,WAAW,GACb,QAAO,eAAe,aAAa,EAAE,CAAC;CAIxC,MAAM,YAAY,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE;CAClD,MAAM,cACJ,cAAc,KACV,IAAI,IAAI,MAAM,SAAS,EAAE,GACzB,IAAI,IAAI,MAAM,SAAS,GAAG,UAAU;CAE1C,MAAM,eAAe,IAAI,gBAAgB,YAAY;CACrD,MAAM,cAAiD,EAAE;AAEzD,MAAK,MAAM,OAAO,aAAa,MAAM,EAAE;EACrC,MAAM,SAAS,aAAa,OAAO,IAAI;EACvC,MAAM,CAAC,cAAc;AAErB,MAAI,OAAO,WAAW,EACpB,aAAY,OAAO;MAEnB,aAAY,OAAO;;AAIvB,QAAO,eAAe,aAAa,YAAY;;AAGjD,MAAa,kBAAkB,OAC7B,KACA,kBACG;AACH,KAAI,CAAC,cACH,QAAO,GAAG,KAAK;CAGjB,MAAM,UAAkC,EAAE;AAE1C,KAAI,QAAQ,SAAS,OAAO,QAAQ;AAClC,UAAQ,OAAO;GACf;AAEF,QAAO,eAAe,eAAe,QAAQ;;AAG/C,MAAa,kBAAkB,OAC7B,KACA,kBACG;AACH,KAAI,CAAC,cACH,QAAO,GAAG,KAAK;CAIjB,MAAM,eAAe,IAAI,QAAQ,IAAI,SAAS,IAAI;CAClD,MAAM,YAAY,IAAI,IAAI,UAAU,aAAa;AAGjD,QAAO,eAAe,eAFN,OAAO,YAAY,UAAU,CAEA;;AAG/C,MAAa,iBAAiB,OAC5B,KACA,iBACG;AACH,KAAI,CAAC,aACH,QAAO,GAAG,KAAK;AAGjB,QAAO,eAAe,cAAc,IAAI,OAAO"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/lib/cache/types.d.ts
|
|
2
|
+
type CacheError = "CacheError" | "InvalidTTLError" | "NotFoundError";
|
|
3
|
+
type CacheOptions<T> = {
|
|
4
|
+
redis: Bun.RedisClient;
|
|
5
|
+
ttl?: number | ((key: string, value: T) => number);
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
serializer?: (value: T) => string;
|
|
9
|
+
deserializer?: (raw: string) => T;
|
|
10
|
+
onError?: (error: {
|
|
11
|
+
type: CacheError;
|
|
12
|
+
message: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { CacheOptions };
|
|
17
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/lib/cache/types.ts"],"mappings":";KAAY,UAAA;AAAA,KAEA,YAAA;EACV,KAAA,EAAO,GAAA,CAAI,WAAA;EACX,GAAA,cAAiB,GAAA,UAAa,KAAA,EAAO,CAAA;EACrC,OAAA;EACA,MAAA;EACA,UAAA,IAAc,KAAA,EAAO,CAAA;EACrB,YAAA,IAAgB,GAAA,aAAgB,CAAA;EAChC,OAAA,IAAW,KAAA;IAAS,IAAA,EAAM,UAAA;IAAY,OAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/lib/cache/types.d.ts
|
|
2
|
+
type CacheError = "CacheError" | "InvalidTTLError" | "NotFoundError";
|
|
3
|
+
type CacheOptions<T> = {
|
|
4
|
+
redis: Bun.RedisClient;
|
|
5
|
+
ttl?: number | ((key: string, value: T) => number);
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
serializer?: (value: T) => string;
|
|
9
|
+
deserializer?: (raw: string) => T;
|
|
10
|
+
onError?: (error: {
|
|
11
|
+
type: CacheError;
|
|
12
|
+
message: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { CacheOptions };
|
|
17
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/lib/cache/types.ts"],"mappings":";KAAY,UAAA;AAAA,KAEA,YAAA;EACV,KAAA,EAAO,GAAA,CAAI,WAAA;EACX,GAAA,cAAiB,GAAA,UAAa,KAAA,EAAO,CAAA;EACrC,OAAA;EACA,MAAA;EACA,UAAA,IAAc,KAAA,EAAO,CAAA;EACrB,YAAA,IAAgB,GAAA,aAAgB,CAAA;EAChC,OAAA,IAAW,KAAA;IAAS,IAAA,EAAM,UAAA;IAAY,OAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//#region src/lib/cron/builder/index.ts
|
|
2
|
+
const CRON_FIELD_ORDER = [
|
|
3
|
+
"second",
|
|
4
|
+
"minute",
|
|
5
|
+
"hour",
|
|
6
|
+
"day",
|
|
7
|
+
"month",
|
|
8
|
+
"weekday"
|
|
9
|
+
];
|
|
10
|
+
var FieldWrapper = class {
|
|
11
|
+
fields = [];
|
|
12
|
+
add(expr) {
|
|
13
|
+
this.fields.push(expr);
|
|
14
|
+
}
|
|
15
|
+
read() {
|
|
16
|
+
return this.fields;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var CronListBuilder = class {
|
|
20
|
+
wrapper;
|
|
21
|
+
constructor(wrapper) {
|
|
22
|
+
this.wrapper = wrapper;
|
|
23
|
+
}
|
|
24
|
+
any() {
|
|
25
|
+
this.wrapper.add({ type: "any" });
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
range(options) {
|
|
29
|
+
this.wrapper.add({
|
|
30
|
+
type: "range",
|
|
31
|
+
...options
|
|
32
|
+
});
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
step(options) {
|
|
36
|
+
this.wrapper.add({
|
|
37
|
+
type: "step",
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
number(value) {
|
|
43
|
+
this.wrapper.add({
|
|
44
|
+
type: "value",
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function range(options) {
|
|
51
|
+
return {
|
|
52
|
+
type: "range",
|
|
53
|
+
...options
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function any() {
|
|
57
|
+
return { type: "any" };
|
|
58
|
+
}
|
|
59
|
+
function step(options) {
|
|
60
|
+
return {
|
|
61
|
+
type: "step",
|
|
62
|
+
...options
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function list(builderFn) {
|
|
66
|
+
const wrapper = new FieldWrapper();
|
|
67
|
+
builderFn(new CronListBuilder(wrapper));
|
|
68
|
+
return {
|
|
69
|
+
type: "list",
|
|
70
|
+
values: wrapper.read()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function number(value) {
|
|
74
|
+
return {
|
|
75
|
+
type: "value",
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function cronJobBuilder(buildFn) {
|
|
80
|
+
const fields = {
|
|
81
|
+
second: void 0,
|
|
82
|
+
minute: void 0,
|
|
83
|
+
hour: void 0,
|
|
84
|
+
day: void 0,
|
|
85
|
+
month: void 0,
|
|
86
|
+
weekday: void 0
|
|
87
|
+
};
|
|
88
|
+
const obj = {
|
|
89
|
+
second(expr) {
|
|
90
|
+
fields.second = checkExpr(expr);
|
|
91
|
+
return obj;
|
|
92
|
+
},
|
|
93
|
+
minute(expr) {
|
|
94
|
+
fields.minute = checkExpr(expr);
|
|
95
|
+
return obj;
|
|
96
|
+
},
|
|
97
|
+
hour(expr) {
|
|
98
|
+
fields.hour = checkExpr(expr);
|
|
99
|
+
return obj;
|
|
100
|
+
},
|
|
101
|
+
day(expr) {
|
|
102
|
+
fields.day = checkExpr(expr);
|
|
103
|
+
return obj;
|
|
104
|
+
},
|
|
105
|
+
month(expr) {
|
|
106
|
+
fields.month = checkExpr(expr);
|
|
107
|
+
return obj;
|
|
108
|
+
},
|
|
109
|
+
weekday(expr) {
|
|
110
|
+
fields.weekday = checkExpr(expr);
|
|
111
|
+
return obj;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
buildFn(obj);
|
|
115
|
+
return generate(fields);
|
|
116
|
+
}
|
|
117
|
+
function checkExpr(expr) {
|
|
118
|
+
if (expr.type === "list") {
|
|
119
|
+
const { values } = expr;
|
|
120
|
+
if (values.length === 0) throw new Error("EmptyListError: List expression cannot be empty");
|
|
121
|
+
return values.map((e) => handleSimpleExpression(e)).join(",");
|
|
122
|
+
}
|
|
123
|
+
return handleSimpleExpression(expr);
|
|
124
|
+
}
|
|
125
|
+
function handleSimpleExpression(expr) {
|
|
126
|
+
switch (expr.type) {
|
|
127
|
+
case "any": return "*";
|
|
128
|
+
case "value": return `${expr.value}`;
|
|
129
|
+
case "range": {
|
|
130
|
+
const { min, max } = expr;
|
|
131
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
132
|
+
return `${min}-${max}`;
|
|
133
|
+
}
|
|
134
|
+
case "step": {
|
|
135
|
+
const { step, range } = expr;
|
|
136
|
+
if (step === 0) throw new Error(`OutOfBoundError: Expected step value greater than zero`);
|
|
137
|
+
if (!range) return `*/${step}`;
|
|
138
|
+
const { min, max } = range;
|
|
139
|
+
if (max === 0) {
|
|
140
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected max value greater than zero`);
|
|
141
|
+
return `${min}-${max}/${step}`;
|
|
142
|
+
}
|
|
143
|
+
if (!max) return `${min}/${step}`;
|
|
144
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
145
|
+
return `${min}-${max}/${step}`;
|
|
146
|
+
}
|
|
147
|
+
default: return "*";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function generate(fields) {
|
|
151
|
+
const parts = [];
|
|
152
|
+
for (let index = 0; index < CRON_FIELD_ORDER.length; index++) {
|
|
153
|
+
const key = CRON_FIELD_ORDER[index];
|
|
154
|
+
if (!key) return "";
|
|
155
|
+
if (key === "second" && !fields[key]) continue;
|
|
156
|
+
parts.push(fields[key] ?? "*");
|
|
157
|
+
}
|
|
158
|
+
return parts.join(" ");
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
exports.any = any;
|
|
162
|
+
exports.cronJobBuilder = cronJobBuilder;
|
|
163
|
+
exports.list = list;
|
|
164
|
+
exports.number = number;
|
|
165
|
+
exports.range = range;
|
|
166
|
+
exports.step = step;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BuilderFn, CronExpr, CronListExpr, CronRange, CronStep } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/cron/builder/index.d.ts
|
|
4
|
+
declare class FieldWrapper<T> {
|
|
5
|
+
private fields;
|
|
6
|
+
add(expr: CronListExpr<T>): void;
|
|
7
|
+
read(): CronListExpr<T>[];
|
|
8
|
+
}
|
|
9
|
+
declare class CronListBuilder<T> {
|
|
10
|
+
private wrapper;
|
|
11
|
+
constructor(wrapper: FieldWrapper<T>);
|
|
12
|
+
any(): CronListBuilder<T>;
|
|
13
|
+
range(options: CronRange<T>): CronListBuilder<T>;
|
|
14
|
+
step(options: CronStep<T>): CronListBuilder<T>;
|
|
15
|
+
number(value: T): CronListBuilder<T>;
|
|
16
|
+
}
|
|
17
|
+
declare function range<T>(options: CronRange<T>): CronExpr<T>;
|
|
18
|
+
declare function any<T>(): CronExpr<T>;
|
|
19
|
+
declare function step<T>(options: CronStep<T>): CronExpr<T>;
|
|
20
|
+
declare function list<T>(builderFn: (builder: CronListBuilder<T>) => CronListBuilder<T>): CronExpr<T>;
|
|
21
|
+
declare function number<T>(value: T): {
|
|
22
|
+
type: "value";
|
|
23
|
+
value: T;
|
|
24
|
+
};
|
|
25
|
+
declare function cronJobBuilder(buildFn: BuilderFn): string;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { any, cronJobBuilder, list, number, range, step };
|
|
28
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/lib/cron/builder/index.ts"],"mappings":";;;cAwBM,YAAA;EAAA,QACI,MAAA;EAED,GAAA,CAAI,IAAA,EAAM,YAAA,CAAa,CAAA;EAIvB,IAAA,CAAA,GAAI,YAAA,CAAA,CAAA;AAAA;AAAA,cAKP,eAAA;EAAA,QACI,OAAA;cAEW,OAAA,EAAS,YAAA,CAAa,CAAA;EAIlC,GAAA,CAAA,GAAO,eAAA,CAAgB,CAAA;EAKvB,KAAA,CAAM,OAAA,EAAS,SAAA,CAAU,CAAA,IAAK,eAAA,CAAgB,CAAA;EAK9C,IAAA,CAAK,OAAA,EAAS,QAAA,CAAS,CAAA,IAAK,eAAA,CAAgB,CAAA;EAK5C,MAAA,CAAO,KAAA,EAAO,CAAA,GAAI,eAAA,CAAgB,CAAA;AAAA;AAAA,iBAM3B,KAAA,GAAA,CAAS,OAAA,EAAS,SAAA,CAAU,CAAA,IAAK,QAAA,CAAS,CAAA;AAAA,iBAI1C,GAAA,GAAA,CAAA,GAAU,QAAA,CAAS,CAAA;AAAA,iBAInB,IAAA,GAAA,CAAQ,OAAA,EAAS,QAAA,CAAS,CAAA,IAAK,QAAA,CAAS,CAAA;AAAA,iBAIxC,IAAA,GAAA,CACd,SAAA,GAAY,OAAA,EAAS,eAAA,CAAgB,CAAA,MAAO,eAAA,CAAgB,CAAA,IAC3D,QAAA,CAAS,CAAA;AAAA,iBAOI,MAAA,GAAA,CAAU,KAAA,EAAO,CAAA;;SAAA,CAAA;AAAA;AAAA,iBAIjB,cAAA,CAAe,OAAA,EAAS,SAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BuilderFn, CronExpr, CronListExpr, CronRange, CronStep } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/cron/builder/index.d.ts
|
|
4
|
+
declare class FieldWrapper<T> {
|
|
5
|
+
private fields;
|
|
6
|
+
add(expr: CronListExpr<T>): void;
|
|
7
|
+
read(): CronListExpr<T>[];
|
|
8
|
+
}
|
|
9
|
+
declare class CronListBuilder<T> {
|
|
10
|
+
private wrapper;
|
|
11
|
+
constructor(wrapper: FieldWrapper<T>);
|
|
12
|
+
any(): CronListBuilder<T>;
|
|
13
|
+
range(options: CronRange<T>): CronListBuilder<T>;
|
|
14
|
+
step(options: CronStep<T>): CronListBuilder<T>;
|
|
15
|
+
number(value: T): CronListBuilder<T>;
|
|
16
|
+
}
|
|
17
|
+
declare function range<T>(options: CronRange<T>): CronExpr<T>;
|
|
18
|
+
declare function any<T>(): CronExpr<T>;
|
|
19
|
+
declare function step<T>(options: CronStep<T>): CronExpr<T>;
|
|
20
|
+
declare function list<T>(builderFn: (builder: CronListBuilder<T>) => CronListBuilder<T>): CronExpr<T>;
|
|
21
|
+
declare function number<T>(value: T): {
|
|
22
|
+
type: "value";
|
|
23
|
+
value: T;
|
|
24
|
+
};
|
|
25
|
+
declare function cronJobBuilder(buildFn: BuilderFn): string;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { any, cronJobBuilder, list, number, range, step };
|
|
28
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/lib/cron/builder/index.ts"],"mappings":";;;cAwBM,YAAA;EAAA,QACI,MAAA;EAED,GAAA,CAAI,IAAA,EAAM,YAAA,CAAa,CAAA;EAIvB,IAAA,CAAA,GAAI,YAAA,CAAA,CAAA;AAAA;AAAA,cAKP,eAAA;EAAA,QACI,OAAA;cAEW,OAAA,EAAS,YAAA,CAAa,CAAA;EAIlC,GAAA,CAAA,GAAO,eAAA,CAAgB,CAAA;EAKvB,KAAA,CAAM,OAAA,EAAS,SAAA,CAAU,CAAA,IAAK,eAAA,CAAgB,CAAA;EAK9C,IAAA,CAAK,OAAA,EAAS,QAAA,CAAS,CAAA,IAAK,eAAA,CAAgB,CAAA;EAK5C,MAAA,CAAO,KAAA,EAAO,CAAA,GAAI,eAAA,CAAgB,CAAA;AAAA;AAAA,iBAM3B,KAAA,GAAA,CAAS,OAAA,EAAS,SAAA,CAAU,CAAA,IAAK,QAAA,CAAS,CAAA;AAAA,iBAI1C,GAAA,GAAA,CAAA,GAAU,QAAA,CAAS,CAAA;AAAA,iBAInB,IAAA,GAAA,CAAQ,OAAA,EAAS,QAAA,CAAS,CAAA,IAAK,QAAA,CAAS,CAAA;AAAA,iBAIxC,IAAA,GAAA,CACd,SAAA,GAAY,OAAA,EAAS,eAAA,CAAgB,CAAA,MAAO,eAAA,CAAgB,CAAA,IAC3D,QAAA,CAAS,CAAA;AAAA,iBAOI,MAAA,GAAA,CAAU,KAAA,EAAO,CAAA;;SAAA,CAAA;AAAA;AAAA,iBAIjB,cAAA,CAAe,OAAA,EAAS,SAAA"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//#region src/lib/cron/builder/index.ts
|
|
2
|
+
const CRON_FIELD_ORDER = [
|
|
3
|
+
"second",
|
|
4
|
+
"minute",
|
|
5
|
+
"hour",
|
|
6
|
+
"day",
|
|
7
|
+
"month",
|
|
8
|
+
"weekday"
|
|
9
|
+
];
|
|
10
|
+
var FieldWrapper = class {
|
|
11
|
+
fields = [];
|
|
12
|
+
add(expr) {
|
|
13
|
+
this.fields.push(expr);
|
|
14
|
+
}
|
|
15
|
+
read() {
|
|
16
|
+
return this.fields;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var CronListBuilder = class {
|
|
20
|
+
wrapper;
|
|
21
|
+
constructor(wrapper) {
|
|
22
|
+
this.wrapper = wrapper;
|
|
23
|
+
}
|
|
24
|
+
any() {
|
|
25
|
+
this.wrapper.add({ type: "any" });
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
range(options) {
|
|
29
|
+
this.wrapper.add({
|
|
30
|
+
type: "range",
|
|
31
|
+
...options
|
|
32
|
+
});
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
step(options) {
|
|
36
|
+
this.wrapper.add({
|
|
37
|
+
type: "step",
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
number(value) {
|
|
43
|
+
this.wrapper.add({
|
|
44
|
+
type: "value",
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function range(options) {
|
|
51
|
+
return {
|
|
52
|
+
type: "range",
|
|
53
|
+
...options
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function any() {
|
|
57
|
+
return { type: "any" };
|
|
58
|
+
}
|
|
59
|
+
function step(options) {
|
|
60
|
+
return {
|
|
61
|
+
type: "step",
|
|
62
|
+
...options
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function list(builderFn) {
|
|
66
|
+
const wrapper = new FieldWrapper();
|
|
67
|
+
builderFn(new CronListBuilder(wrapper));
|
|
68
|
+
return {
|
|
69
|
+
type: "list",
|
|
70
|
+
values: wrapper.read()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function number(value) {
|
|
74
|
+
return {
|
|
75
|
+
type: "value",
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function cronJobBuilder(buildFn) {
|
|
80
|
+
const fields = {
|
|
81
|
+
second: void 0,
|
|
82
|
+
minute: void 0,
|
|
83
|
+
hour: void 0,
|
|
84
|
+
day: void 0,
|
|
85
|
+
month: void 0,
|
|
86
|
+
weekday: void 0
|
|
87
|
+
};
|
|
88
|
+
const obj = {
|
|
89
|
+
second(expr) {
|
|
90
|
+
fields.second = checkExpr(expr);
|
|
91
|
+
return obj;
|
|
92
|
+
},
|
|
93
|
+
minute(expr) {
|
|
94
|
+
fields.minute = checkExpr(expr);
|
|
95
|
+
return obj;
|
|
96
|
+
},
|
|
97
|
+
hour(expr) {
|
|
98
|
+
fields.hour = checkExpr(expr);
|
|
99
|
+
return obj;
|
|
100
|
+
},
|
|
101
|
+
day(expr) {
|
|
102
|
+
fields.day = checkExpr(expr);
|
|
103
|
+
return obj;
|
|
104
|
+
},
|
|
105
|
+
month(expr) {
|
|
106
|
+
fields.month = checkExpr(expr);
|
|
107
|
+
return obj;
|
|
108
|
+
},
|
|
109
|
+
weekday(expr) {
|
|
110
|
+
fields.weekday = checkExpr(expr);
|
|
111
|
+
return obj;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
buildFn(obj);
|
|
115
|
+
return generate(fields);
|
|
116
|
+
}
|
|
117
|
+
function checkExpr(expr) {
|
|
118
|
+
if (expr.type === "list") {
|
|
119
|
+
const { values } = expr;
|
|
120
|
+
if (values.length === 0) throw new Error("EmptyListError: List expression cannot be empty");
|
|
121
|
+
return values.map((e) => handleSimpleExpression(e)).join(",");
|
|
122
|
+
}
|
|
123
|
+
return handleSimpleExpression(expr);
|
|
124
|
+
}
|
|
125
|
+
function handleSimpleExpression(expr) {
|
|
126
|
+
switch (expr.type) {
|
|
127
|
+
case "any": return "*";
|
|
128
|
+
case "value": return `${expr.value}`;
|
|
129
|
+
case "range": {
|
|
130
|
+
const { min, max } = expr;
|
|
131
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
132
|
+
return `${min}-${max}`;
|
|
133
|
+
}
|
|
134
|
+
case "step": {
|
|
135
|
+
const { step, range } = expr;
|
|
136
|
+
if (step === 0) throw new Error(`OutOfBoundError: Expected step value greater than zero`);
|
|
137
|
+
if (!range) return `*/${step}`;
|
|
138
|
+
const { min, max } = range;
|
|
139
|
+
if (max === 0) {
|
|
140
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected max value greater than zero`);
|
|
141
|
+
return `${min}-${max}/${step}`;
|
|
142
|
+
}
|
|
143
|
+
if (!max) return `${min}/${step}`;
|
|
144
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
145
|
+
return `${min}-${max}/${step}`;
|
|
146
|
+
}
|
|
147
|
+
default: return "*";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function generate(fields) {
|
|
151
|
+
const parts = [];
|
|
152
|
+
for (let index = 0; index < CRON_FIELD_ORDER.length; index++) {
|
|
153
|
+
const key = CRON_FIELD_ORDER[index];
|
|
154
|
+
if (!key) return "";
|
|
155
|
+
if (key === "second" && !fields[key]) continue;
|
|
156
|
+
parts.push(fields[key] ?? "*");
|
|
157
|
+
}
|
|
158
|
+
return parts.join(" ");
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
export { any, cronJobBuilder, list, number, range, step };
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/lib/cron/builder/index.ts"],"sourcesContent":["import type {\n BuilderFn,\n CronBuilderType,\n CronExpr,\n CronField,\n CronListExpr,\n CronRange,\n CronStep,\n DayType,\n HourType,\n MonthType,\n TimeType,\n WeekDayType,\n} from \"./types.js\";\n\nconst CRON_FIELD_ORDER: CronField[] = [\n \"second\",\n \"minute\",\n \"hour\",\n \"day\",\n \"month\",\n \"weekday\",\n] as const;\n\nclass FieldWrapper<T> {\n private fields: CronListExpr<T>[] = [];\n\n public add(expr: CronListExpr<T>) {\n this.fields.push(expr);\n }\n\n public read() {\n return this.fields;\n }\n}\n\nclass CronListBuilder<T> {\n private wrapper: FieldWrapper<T>;\n\n public constructor(wrapper: FieldWrapper<T>) {\n this.wrapper = wrapper;\n }\n\n public any(): CronListBuilder<T> {\n this.wrapper.add({ type: \"any\" });\n return this;\n }\n\n public range(options: CronRange<T>): CronListBuilder<T> {\n this.wrapper.add({ type: \"range\", ...options });\n return this;\n }\n\n public step(options: CronStep<T>): CronListBuilder<T> {\n this.wrapper.add({ type: \"step\", ...options });\n return this;\n }\n\n public number(value: T): CronListBuilder<T> {\n this.wrapper.add({ type: \"value\", value: value });\n return this;\n }\n}\n\nexport function range<T>(options: CronRange<T>): CronExpr<T> {\n return { type: \"range\", ...options };\n}\n\nexport function any<T>(): CronExpr<T> {\n return { type: \"any\" };\n}\n\nexport function step<T>(options: CronStep<T>): CronExpr<T> {\n return { type: \"step\", ...options };\n}\n\nexport function list<T>(\n builderFn: (builder: CronListBuilder<T>) => CronListBuilder<T>,\n): CronExpr<T> {\n const wrapper = new FieldWrapper<T>();\n builderFn(new CronListBuilder<T>(wrapper));\n\n return { type: \"list\", values: wrapper.read() };\n}\n\nexport function number<T>(value: T) {\n return { type: \"value\", value: value } satisfies CronExpr<T>;\n}\n\nexport function cronJobBuilder(buildFn: BuilderFn) {\n const fields: Partial<Record<CronField, string>> = {\n second: undefined,\n minute: undefined,\n hour: undefined,\n day: undefined,\n month: undefined,\n weekday: undefined,\n };\n\n const obj: CronBuilderType = {\n second(expr: CronExpr<TimeType>) {\n fields.second = checkExpr(expr);\n return obj;\n },\n minute(expr: CronExpr<TimeType>) {\n fields.minute = checkExpr(expr);\n return obj;\n },\n hour(expr: CronExpr<HourType>) {\n fields.hour = checkExpr(expr);\n return obj;\n },\n day(expr: CronExpr<DayType>) {\n fields.day = checkExpr(expr);\n return obj;\n },\n month(expr: CronExpr<MonthType>) {\n fields.month = checkExpr(expr);\n return obj;\n },\n weekday(expr: CronExpr<WeekDayType>) {\n fields.weekday = checkExpr(expr);\n return obj;\n },\n };\n\n buildFn(obj);\n return generate(fields);\n}\n\nfunction checkExpr<T>(expr: CronExpr<T>) {\n if (expr.type === \"list\") {\n const { values } = expr;\n if (values.length === 0) {\n throw new Error(\"EmptyListError: List expression cannot be empty\");\n }\n\n const data = values.map((e) => handleSimpleExpression(e));\n\n return data.join(\",\");\n }\n\n return handleSimpleExpression(expr);\n}\n\nfunction handleSimpleExpression<T>(expr: CronExpr<T>) {\n switch (expr.type) {\n case \"any\": {\n return \"*\";\n }\n\n case \"value\": {\n return `${expr.value}`;\n }\n\n case \"range\": {\n const { min, max } = expr;\n if (min > max) {\n throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);\n }\n\n return `${min}-${max}`;\n }\n\n case \"step\": {\n const { step, range } = expr;\n\n if (step === 0) {\n throw new Error(\n `OutOfBoundError: Expected step value greater than zero`,\n );\n }\n\n if (!range) {\n return `*/${step}`;\n }\n\n const { min, max } = range;\n\n if (max === 0) {\n if (min > max) {\n throw new Error(\n `OutOfBoundError: Expected max value greater than zero`,\n );\n }\n\n return `${min}-${max}/${step}`;\n }\n\n if (!max) {\n return `${min}/${step}`;\n }\n\n if (min > max) {\n throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);\n }\n\n return `${min}-${max}/${step}`;\n }\n\n default: {\n return \"*\";\n }\n }\n}\n\nfunction generate(fields: Partial<Record<CronField, string>>): string {\n const parts: string[] = [];\n\n for (let index = 0; index < CRON_FIELD_ORDER.length; index++) {\n const key = CRON_FIELD_ORDER[index];\n if (!key) return \"\";\n if (key === \"second\" && !fields[key]) {\n continue;\n }\n\n parts.push(fields[key] ?? \"*\");\n }\n\n return parts.join(\" \");\n}\n"],"mappings":";AAeA,MAAM,mBAAgC;CACpC;CACA;CACA;CACA;CACA;CACA;CACD;AAED,IAAM,eAAN,MAAsB;CACpB,SAAoC,EAAE;CAEtC,IAAW,MAAuB;AAChC,OAAK,OAAO,KAAK,KAAK;;CAGxB,OAAc;AACZ,SAAO,KAAK;;;AAIhB,IAAM,kBAAN,MAAyB;CACvB;CAEA,YAAmB,SAA0B;AAC3C,OAAK,UAAU;;CAGjB,MAAiC;AAC/B,OAAK,QAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACjC,SAAO;;CAGT,MAAa,SAA2C;AACtD,OAAK,QAAQ,IAAI;GAAE,MAAM;GAAS,GAAG;GAAS,CAAC;AAC/C,SAAO;;CAGT,KAAY,SAA0C;AACpD,OAAK,QAAQ,IAAI;GAAE,MAAM;GAAQ,GAAG;GAAS,CAAC;AAC9C,SAAO;;CAGT,OAAc,OAA8B;AAC1C,OAAK,QAAQ,IAAI;GAAE,MAAM;GAAgB;GAAO,CAAC;AACjD,SAAO;;;AAIX,SAAgB,MAAS,SAAoC;AAC3D,QAAO;EAAE,MAAM;EAAS,GAAG;EAAS;;AAGtC,SAAgB,MAAsB;AACpC,QAAO,EAAE,MAAM,OAAO;;AAGxB,SAAgB,KAAQ,SAAmC;AACzD,QAAO;EAAE,MAAM;EAAQ,GAAG;EAAS;;AAGrC,SAAgB,KACd,WACa;CACb,MAAM,UAAU,IAAI,cAAiB;AACrC,WAAU,IAAI,gBAAmB,QAAQ,CAAC;AAE1C,QAAO;EAAE,MAAM;EAAQ,QAAQ,QAAQ,MAAM;EAAE;;AAGjD,SAAgB,OAAU,OAAU;AAClC,QAAO;EAAE,MAAM;EAAgB;EAAO;;AAGxC,SAAgB,eAAe,SAAoB;CACjD,MAAM,SAA6C;EACjD,QAAQ,KAAA;EACR,QAAQ,KAAA;EACR,MAAM,KAAA;EACN,KAAK,KAAA;EACL,OAAO,KAAA;EACP,SAAS,KAAA;EACV;CAED,MAAM,MAAuB;EAC3B,OAAO,MAA0B;AAC/B,UAAO,SAAS,UAAU,KAAK;AAC/B,UAAO;;EAET,OAAO,MAA0B;AAC/B,UAAO,SAAS,UAAU,KAAK;AAC/B,UAAO;;EAET,KAAK,MAA0B;AAC7B,UAAO,OAAO,UAAU,KAAK;AAC7B,UAAO;;EAET,IAAI,MAAyB;AAC3B,UAAO,MAAM,UAAU,KAAK;AAC5B,UAAO;;EAET,MAAM,MAA2B;AAC/B,UAAO,QAAQ,UAAU,KAAK;AAC9B,UAAO;;EAET,QAAQ,MAA6B;AACnC,UAAO,UAAU,UAAU,KAAK;AAChC,UAAO;;EAEV;AAED,SAAQ,IAAI;AACZ,QAAO,SAAS,OAAO;;AAGzB,SAAS,UAAa,MAAmB;AACvC,KAAI,KAAK,SAAS,QAAQ;EACxB,MAAM,EAAE,WAAW;AACnB,MAAI,OAAO,WAAW,EACpB,OAAM,IAAI,MAAM,kDAAkD;AAKpE,SAFa,OAAO,KAAK,MAAM,uBAAuB,EAAE,CAAC,CAE7C,KAAK,IAAI;;AAGvB,QAAO,uBAAuB,KAAK;;AAGrC,SAAS,uBAA0B,MAAmB;AACpD,SAAQ,KAAK,MAAb;EACE,KAAK,MACH,QAAO;EAGT,KAAK,QACH,QAAO,GAAG,KAAK;EAGjB,KAAK,SAAS;GACZ,MAAM,EAAE,KAAK,QAAQ;AACrB,OAAI,MAAM,IACR,OAAM,IAAI,MAAM,6BAA6B,IAAI,MAAM,MAAM;AAG/D,UAAO,GAAG,IAAI,GAAG;;EAGnB,KAAK,QAAQ;GACX,MAAM,EAAE,MAAM,UAAU;AAExB,OAAI,SAAS,EACX,OAAM,IAAI,MACR,yDACD;AAGH,OAAI,CAAC,MACH,QAAO,KAAK;GAGd,MAAM,EAAE,KAAK,QAAQ;AAErB,OAAI,QAAQ,GAAG;AACb,QAAI,MAAM,IACR,OAAM,IAAI,MACR,wDACD;AAGH,WAAO,GAAG,IAAI,GAAG,IAAI,GAAG;;AAG1B,OAAI,CAAC,IACH,QAAO,GAAG,IAAI,GAAG;AAGnB,OAAI,MAAM,IACR,OAAM,IAAI,MAAM,6BAA6B,IAAI,MAAM,MAAM;AAG/D,UAAO,GAAG,IAAI,GAAG,IAAI,GAAG;;EAG1B,QACE,QAAO;;;AAKb,SAAS,SAAS,QAAoD;CACpE,MAAM,QAAkB,EAAE;AAE1B,MAAK,IAAI,QAAQ,GAAG,QAAQ,iBAAiB,QAAQ,SAAS;EAC5D,MAAM,MAAM,iBAAiB;AAC7B,MAAI,CAAC,IAAK,QAAO;AACjB,MAAI,QAAQ,YAAY,CAAC,OAAO,KAC9B;AAGF,QAAM,KAAK,OAAO,QAAQ,IAAI;;AAGhC,QAAO,MAAM,KAAK,IAAI"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/lib/cron/builder/types.ts
|
|
2
|
+
const WeekDay = {
|
|
3
|
+
sun: 0,
|
|
4
|
+
mon: 1,
|
|
5
|
+
tue: 2,
|
|
6
|
+
wed: 3,
|
|
7
|
+
thu: 4,
|
|
8
|
+
fri: 5,
|
|
9
|
+
sat: 6
|
|
10
|
+
};
|
|
11
|
+
const Month = {
|
|
12
|
+
jan: 1,
|
|
13
|
+
feb: 2,
|
|
14
|
+
mar: 3,
|
|
15
|
+
apr: 4,
|
|
16
|
+
may: 5,
|
|
17
|
+
jun: 6,
|
|
18
|
+
jul: 7,
|
|
19
|
+
aug: 8,
|
|
20
|
+
sep: 9,
|
|
21
|
+
oct: 10,
|
|
22
|
+
nov: 11,
|
|
23
|
+
dec: 12
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.Month = Month;
|
|
27
|
+
exports.WeekDay = WeekDay;
|