@ditojs/server 1.26.0 → 1.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/server",
3
- "version": "1.26.0",
3
+ "version": "1.27.1",
4
4
  "type": "module",
5
5
  "description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/server",
@@ -22,10 +22,10 @@
22
22
  "node >= 18"
23
23
  ],
24
24
  "dependencies": {
25
- "@ditojs/admin": "^1.26.0",
25
+ "@ditojs/admin": "^1.27.0",
26
26
  "@ditojs/build": "^1.25.0",
27
- "@ditojs/router": "^1.26.0",
28
- "@ditojs/utils": "^1.26.0",
27
+ "@ditojs/router": "^1.27.0",
28
+ "@ditojs/utils": "^1.27.0",
29
29
  "@koa/cors": "^4.0.0",
30
30
  "@koa/multer": "^3.0.2",
31
31
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -51,7 +51,7 @@
51
51
  "koa-static": "^5.0.0",
52
52
  "mime-types": "^2.1.35",
53
53
  "multer": "^1.4.5-lts.1",
54
- "multer-s3": "^3.0.1",
54
+ "multer-s3": "https://github.com/ditojs/multer-s3#dito",
55
55
  "nanoid": "^4.0.1",
56
56
  "parse-duration": "^1.0.3",
57
57
  "passport-local": "^1.0.0",
@@ -90,7 +90,7 @@
90
90
  "typescript": "^4.9.5"
91
91
  },
92
92
  "types": "types",
93
- "gitHead": "198c9832c863003c8c8fcd147bf61a5f99a39c91",
93
+ "gitHead": "b0658f0d25d0a234a4b7a3ad2df957a92a0d37e7",
94
94
  "scripts": {
95
95
  "types": "tsc --noEmit ./src/index.d.ts"
96
96
  },
@@ -31,7 +31,8 @@ import { Controller, AdminController } from '../controllers/index.js'
31
31
  import { Service } from '../services/index.js'
32
32
  import { Storage } from '../storage/index.js'
33
33
  import { convertSchema } from '../schema/index.js'
34
- import { getDuration, subtractDuration, deprecate } from '../utils/index.js'
34
+ import { getDuration, subtractDuration } from '../utils/duration.js'
35
+ import { deprecate } from '../utils/deprecate.js'
35
36
  import {
36
37
  ResponseError,
37
38
  ValidationError,
@@ -881,7 +882,9 @@ export class Application extends Koa {
881
882
  data = await fs.readFile(filepath)
882
883
  } else {
883
884
  const response = await fetch(url)
884
- data = await response.arrayBuffer()
885
+ const arrayBuffer = await response.arrayBuffer()
886
+ // `fs.writeFile()` expects a Buffer, not an ArrayBuffer.
887
+ data = Buffer.from(arrayBuffer)
885
888
  }
886
889
  }
887
890
  const importedFile = await storage.addFile(file, data)
@@ -2,7 +2,7 @@ import objection from 'objection'
2
2
  import Ajv from 'ajv/dist/2020.js'
3
3
  import addFormats from 'ajv-formats'
4
4
  import { isArray, isObject, clone, isAsync, isPromise } from '@ditojs/utils'
5
- import { formatJson } from '../utils/index.js'
5
+ import { formatJson } from '../utils/json.js'
6
6
  import * as schema from '../schema/index.js'
7
7
 
8
8
  // Dito does not rely on objection.AjvValidator but instead implements its own
@@ -1,10 +1,14 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs/promises'
3
3
  import pico from 'picocolors'
4
- import { getRelationClass, isThroughRelationClass } from '@ditojs/server'
4
+ import {
5
+ getRelationClass,
6
+ isThroughRelationClass
7
+ } from '@ditojs/server'
5
8
  import {
6
9
  isObject, isArray, isString, deindent, capitalize
7
10
  } from '@ditojs/utils'
11
+ import { exists } from '../../utils/fs.js'
8
12
 
9
13
  const typeToKnex = {
10
14
  number: 'double',
@@ -204,12 +208,3 @@ function getTimestamp() {
204
208
  padDate(d.getMinutes()) +
205
209
  padDate(d.getSeconds())
206
210
  }
207
-
208
- async function exists(path) {
209
- try {
210
- await fs.access(path)
211
- return true
212
- } catch {
213
- return false
214
- }
215
- }
@@ -1,4 +1,4 @@
1
- import { formatJson } from '@ditojs/server'
1
+ import { formatJson } from '../../utils/json.js'
2
2
 
3
3
  export async function listAssetConfig(app, ...args) {
4
4
  const assetConfig = app.getAssetConfig({
@@ -15,7 +15,9 @@ import { merge } from '@ditojs/utils'
15
15
  import { Controller } from './Controller.js'
16
16
  import { handleConnectMiddleware } from '../middleware/index.js'
17
17
  import { ControllerError } from '../errors/index.js'
18
- import { formatJson, getRandomFreePort, deprecate } from '../utils/index.js'
18
+ import { getRandomFreePort } from '../utils/net.js'
19
+ import { formatJson } from '../utils/json.js'
20
+ import { deprecate } from '../utils/deprecate.js'
19
21
 
20
22
  export class AdminController extends Controller {
21
23
  // @override
@@ -6,9 +6,12 @@ import {
6
6
  ResponseError, ControllerError, AuthorizationError
7
7
  } from '../errors/index.js'
8
8
  import {
9
- getOwnProperty, getOwnKeys, getAllKeys, getInheritanceChain,
10
- processHandlerParameters, describeFunction, formatJson, deprecate
11
- } from '../utils/index.js'
9
+ getOwnProperty, getOwnKeys, getAllKeys, getInheritanceChain
10
+ } from '../utils/object.js'
11
+ import { processHandlerParameters } from '../utils/handler.js'
12
+ import { describeFunction } from '../utils/function.js'
13
+ import { formatJson } from '../utils/json.js'
14
+ import { deprecate } from '../utils/deprecate.js'
12
15
  import {
13
16
  isObject, isString, isArray, isBoolean, isFunction, asArray, equals,
14
17
  parseDataPath, normalizeDataPath
@@ -3,7 +3,7 @@ import { isObject, camelize } from '@ditojs/utils'
3
3
  import { CollectionController } from './CollectionController.js'
4
4
  import { RelationController } from './RelationController.js'
5
5
  import { ControllerError } from '../errors/index.js'
6
- import { setupPropertyInheritance } from '../utils/index.js'
6
+ import { setupPropertyInheritance } from '../utils/object.js'
7
7
 
8
8
  export class ModelController extends CollectionController {
9
9
  configure() {
@@ -2,7 +2,8 @@ import pico from 'picocolors'
2
2
  import { asArray } from '@ditojs/utils'
3
3
  import { CollectionController } from './CollectionController.js'
4
4
  import { ControllerError } from '../errors/index.js'
5
- import { setupPropertyInheritance, getScope } from '../utils/index.js'
5
+ import { setupPropertyInheritance } from '../utils/object.js'
6
+ import { getScope } from '../utils/scope.js'
6
7
 
7
8
  export class RelationController extends CollectionController {
8
9
  constructor(parent, object, relationInstance, relationDefinition) {
@@ -1,4 +1,4 @@
1
- import { createDecorator } from '../utils/index.js'
1
+ import { createDecorator } from '../utils/decorator.js'
2
2
 
3
3
  export function action(method, path) {
4
4
  return createDecorator(value => {
@@ -1,4 +1,4 @@
1
- import { createDecorator } from '../utils/index.js'
1
+ import { createDecorator } from '../utils/decorator.js'
2
2
 
3
3
  export function authorize(authorize) {
4
4
  return createDecorator(value => {
@@ -1,5 +1,7 @@
1
1
  import { isArray, isObject } from '@ditojs/utils'
2
- import { createDecorator, deprecate, formatJson } from '../utils/index.js'
2
+ import { createDecorator } from '../utils/decorator.js'
3
+ import { formatJson } from '../utils/json.js'
4
+ import { deprecate } from '../utils/deprecate.js'
3
5
 
4
6
  export function parameters(parameters, options) {
5
7
  if (isObject(parameters)) {
@@ -1,5 +1,6 @@
1
1
  import { isObject } from '@ditojs/utils'
2
- import { createDecorator, formatJson } from '../utils/index.js'
2
+ import { createDecorator } from '../utils/decorator.js'
3
+ import { formatJson } from '../utils/json.js'
3
4
 
4
5
  export function returns(returns, options) {
5
6
  if (!isObject(returns)) {
@@ -1,4 +1,4 @@
1
- import { createDecorator } from '../utils/index.js'
1
+ import { createDecorator } from '../utils/decorator.js'
2
2
 
3
3
  export function scope(...scopes) {
4
4
  return createDecorator(value => {
@@ -1,4 +1,4 @@
1
- import { createDecorator } from '../utils/index.js'
1
+ import { createDecorator } from '../utils/decorator.js'
2
2
 
3
3
  export const transacted = createDecorator(value => {
4
4
  value.transacted = true
package/src/index.js CHANGED
@@ -8,4 +8,3 @@ export * from './controllers/index.js'
8
8
  export * from './services/index.js'
9
9
  export * from './decorators/index.js'
10
10
  export * from './storage/index.js'
11
- export * from './utils/index.js'
@@ -1,5 +1,5 @@
1
1
  import { transaction } from 'objection'
2
- import { emitAsync } from '../utils/index.js'
2
+ import { emitAsync } from '../utils/emitter.js'
3
3
 
4
4
  export function createTransaction() {
5
5
  return async (ctx, next) => {
@@ -12,7 +12,7 @@ import {
12
12
  convertRelations
13
13
  } from '../schema/index.js'
14
14
  import { populateGraph, filterGraph } from '../graph/index.js'
15
- import { formatJson } from '../utils/index.js'
15
+ import { formatJson } from '../utils/json.js'
16
16
  import {
17
17
  ResponseError,
18
18
  GraphError, ModelError,
@@ -1,4 +1,4 @@
1
- import { mergeReversedOrNull } from '../../utils/index.js'
1
+ import { mergeReversedOrNull } from '../../utils/object.js'
2
2
 
3
3
  export default function assets(values) {
4
4
  return mergeReversedOrNull(values)
@@ -1,5 +1,6 @@
1
1
  import { isObject, isFunction } from '@ditojs/utils'
2
- import { mergeReversed, processHandlerParameters } from '../../utils/index.js'
2
+ import { processHandlerParameters } from '../../utils/handler.js'
3
+ import { mergeReversed } from '../../utils/object.js'
3
4
  import { QueryFilters } from '../../query/index.js'
4
5
 
5
6
  export default function filters(values) {
@@ -1,4 +1,4 @@
1
- import { mergeAsReversedArrays } from '../../utils/index.js'
1
+ import { mergeAsReversedArrays } from '../../utils/object.js'
2
2
 
3
3
  export default function hooks(values) {
4
4
  // Use `mergeAsReversedArrays()` so that for each event there is an array
@@ -1,4 +1,4 @@
1
- import { mergeReversed } from '../../utils/index.js'
1
+ import { mergeReversed } from '../../utils/object.js'
2
2
 
3
3
  export default function modifiers(values) {
4
4
  return mergeReversed(values)
@@ -1,4 +1,4 @@
1
- import { mergeReversed } from '../../utils/index.js'
1
+ import { mergeReversed } from '../../utils/object.js'
2
2
 
3
3
  export default function hooks(values) {
4
4
  return mergeReversed(values)
@@ -1,4 +1,4 @@
1
- import { mergeReversed } from '../../utils/index.js'
1
+ import { mergeReversed } from '../../utils/object.js'
2
2
 
3
3
  export default function properties(values) {
4
4
  const properties = mergeReversed(values)
@@ -1,4 +1,4 @@
1
- import { mergeReversed } from '../../utils/index.js'
1
+ import { mergeReversed } from '../../utils/object.js'
2
2
 
3
3
  export default function relations(values) {
4
4
  return mergeReversed(values)
@@ -1,4 +1,4 @@
1
- import { mergeReversed } from '../../utils/index.js'
1
+ import { mergeReversed } from '../../utils/object.js'
2
2
 
3
3
  export default function schema(values) {
4
4
  return mergeReversed(values)
@@ -1,6 +1,6 @@
1
1
  import { isObject, isFunction } from '@ditojs/utils'
2
2
  import { ModelError } from '../../errors/index.js'
3
- import { mergeReversed } from '../../utils/index.js'
3
+ import { mergeReversed } from '../../utils/object.js'
4
4
 
5
5
  export default function scopes(values) {
6
6
  const scopes = {}
@@ -7,7 +7,9 @@ import { QueryParameters } from './QueryParameters.js'
7
7
  import { KnexHelper } from '../lib/index.js'
8
8
  import { DitoGraphProcessor, walkGraph } from '../graph/index.js'
9
9
  import { QueryBuilderError, RelationError } from '../errors/index.js'
10
- import { createLookup, getScope, deprecate } from '../utils/index.js'
10
+ import { createLookup } from '../utils/object.js'
11
+ import { getScope } from '../utils/scope.js'
12
+ import { deprecate } from '../utils/deprecate.js'
11
13
 
12
14
  const SYMBOL_ALL = Symbol('all')
13
15
 
@@ -0,0 +1,10 @@
1
+ import fs from 'fs/promises'
2
+
3
+ export async function exists(path) {
4
+ try {
5
+ await fs.access(path)
6
+ return true
7
+ } catch {
8
+ return false
9
+ }
10
+ }
package/types/index.d.ts CHANGED
@@ -5,10 +5,10 @@
5
5
 
6
6
  // Export the entire Dito namespace.
7
7
 
8
+ import { ObjectCannedACL, S3ClientConfig } from '@aws-sdk/client-s3'
8
9
  import { DateFormat } from '@dito/utils'
9
10
  import koaCors from '@koa/cors'
10
11
  import * as Ajv from 'ajv/dist/2020.js'
11
- import * as aws from 'aws-sdk'
12
12
  import * as dbErrors from 'db-errors'
13
13
  import * as EventEmitter2 from 'eventemitter2'
14
14
  import helmet from 'helmet'
@@ -21,6 +21,7 @@ import mount from 'koa-mount'
21
21
  import koaPinoLogger from 'koa-pino-logger'
22
22
  import koaResponseTime from 'koa-response-time'
23
23
  import koaSession from 'koa-session'
24
+ import multerS3 from 'multer-s3'
24
25
  import * as objection from 'objection'
25
26
  import { KnexSnakeCaseMappersFactory } from 'objection'
26
27
  import { Logger } from 'pino'
@@ -212,61 +213,39 @@ export type MulterS3File = {
212
213
 
213
214
  export type StorageConfigs = { [key: string]: StorageConfig }
214
215
 
215
- export type StorageConfig =
216
- | {
217
- type: 's3'
218
- /** The name of the destination bucket. */
219
- bucket: aws.S3.BucketName
220
- /** @default 'private' */
221
- acl: LiteralUnion<
222
- | 'private'
223
- | 'public-read'
224
- | 'public-read-write'
225
- | 'authenticated-read'
226
- | 'aws-exec-read'
227
- | 'bucket-owner-read'
228
- | 'bucket-owner-full-control'
229
- >
230
- /**
231
- * Can be used to specify caching behavior along the request/reply chain.
232
- *
233
- * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.
234
- */
235
- cacheControl?: aws.S3.CacheControl
236
- /**
237
- * The type of storage to use for the object.
238
- *
239
- * @default 'STANDARD'
240
- */
241
- storageClass?: LiteralUnion<
242
- | 'STANDARD'
243
- | 'REDUCED_REDUNDANCY'
244
- | 'STANDARD_IA'
245
- | 'ONEZONE_IA'
246
- | 'INTELLIGENT_TIERING'
247
- | 'GLACIER'
248
- | 'DEEP_ARCHIVE'
249
- >
250
- /**
251
- * The server-side encryption algorithm used when storing this object in
252
- * Amazon S3 (for example, AES256, aws:kms).
253
- */
254
- serverSideEncryption?: aws.S3.ServerSideEncryption
255
- /**
256
- * If present, specifies the ID of the AWS Key Management Service (AWS
257
- * KMS) symmetric customer managed customer master key (CMK)
258
- */
259
- sseKmsKeyId?: aws.S3.SSEKMSKeyId
260
- s3: aws.S3.ClientConfiguration
261
- url?: string
262
- }
263
- | {
264
- type: 'disk'
265
- path: string
266
- url?: string
267
- mount?: string
268
- allowedImports?: string[]
269
- }
216
+ type CommonStorageConfig = {
217
+ /**
218
+ * The concurrency at which assets are added to storage.
219
+ *
220
+ * @default `8`
221
+ */
222
+ concurrency?: number
223
+ /**
224
+ * The base URL at which assets are accessible.
225
+ */
226
+ url?: string
227
+ allowedImports?: string[]
228
+ }
229
+
230
+ export type S3StorageConfig = CommonStorageConfig & {
231
+ type: 's3'
232
+ bucket: string
233
+ acl?: ObjectCannedACL | string
234
+ s3: S3ClientConfig
235
+ } & Omit<
236
+ Parameters<typeof multerS3>[0],
237
+ 's3' | 'key' | 'contentType' | 'metadata'
238
+ >
239
+
240
+ export type DiskStorageConfig = CommonStorageConfig & {
241
+ type: 'disk'
242
+ /**
243
+ * The path to the directory where assets are stored on.
244
+ */
245
+ path: string
246
+ }
247
+
248
+ export type StorageConfig = S3StorageConfig | DiskStorageConfig
270
249
 
271
250
  export interface AdminConfig {
272
251
  api?: ApiConfig
@@ -784,8 +763,7 @@ export class Model extends objection.Model {
784
763
  static whereJsonSubsetOf: StaticQueryBuilderMethod<'whereJsonSubsetOf'>
785
764
  static whereJsonNotSubsetOf: StaticQueryBuilderMethod<'whereJsonNotSubsetOf'>
786
765
  static whereJsonSupersetOf: StaticQueryBuilderMethod<'whereJsonSupersetOf'>
787
- static whereJsonNotSupersetOf:
788
- StaticQueryBuilderMethod<'whereJsonNotSupersetOf'>
766
+ static whereJsonNotSupersetOf: StaticQueryBuilderMethod<'whereJsonNotSupersetOf'>
789
767
 
790
768
  static having: StaticQueryBuilderMethod<'having'>
791
769
  static havingIn: StaticQueryBuilderMethod<'havingIn'>
@@ -885,6 +863,16 @@ export class Controller {
885
863
  initialize(): Promise<void>
886
864
  // TODO: type reflectActionsObject
887
865
  reflectActionsObject(): any
866
+ /**
867
+ * @overridable
868
+ */
869
+ logController(): void
870
+ /**
871
+ * @param str The string to log.
872
+ * @param [indent=0] The amount of levels to indent (in pairs of two spaces).
873
+ * Default is `0`
874
+ */
875
+ logRoute(str: string, indent?: number): void
888
876
  setupRoute<$ControllerAction extends ControllerAction = ControllerAction>(
889
877
  method: HTTPMethod,
890
878
  url: string,
@@ -930,12 +918,6 @@ export class Controller {
930
918
  processAuthorize(authorize: any): any
931
919
  describeAuthorize(authorize: any): string
932
920
  handleAuthorization(): Promise<void>
933
- /**
934
- * @param str The string to log.
935
- * @param [indent=0] The amount of levels to indent (in pairs of two spaces).
936
- * Default is `0`
937
- */
938
- log(str: string, indent?: number): void
939
921
  }
940
922
 
941
923
  export type ActionParameter = Schema & { name: string }
@@ -1,10 +0,0 @@
1
- export * from './date.js'
2
- export * from './decorator.js'
3
- export * from './deprecate.js'
4
- export * from './emitter.js'
5
- export * from './function.js'
6
- export * from './handler.js'
7
- export * from './json.js'
8
- export * from './net.js'
9
- export * from './object.js'
10
- export * from './scope.js'
File without changes