Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
617 changes: 286 additions & 331 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Auth/Drivers/Driver.imba
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default class Driver
if isValid !== true
let errors = {}

isValid.forEach do(field)
for field in isValid
errors[field] = [
"The {field} is invalid or has already taken."
]
Expand Down
39 changes: 29 additions & 10 deletions src/Database/Database.imba
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ try
let results\object[] = await this

if columns && Array.isArray(columns) && columns.length > 0
return results.map do(result)
let mappedResults = []
for result in results
const object = {}

for column in columns
object[column] = result[column]

return object
mappedResults.push(object)
return mappedResults

if this._hidden && Array.isArray(this._hidden) && this._hidden.length > 0
for result in results
Expand Down Expand Up @@ -129,37 +129,56 @@ try

url = url.length > 1 ? url.replace(/\/+$/, '') + '/' : ''

params = []
keys = Object.keys(query)
for key in keys
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.firstPage) : query[key]))
links.firstPage = {
label: 'First',
active: results.pagination.firstPage === results.pagination.currentPage,
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.firstPage) : query[key])).join('&')
url: url + '?' + params.join('&')
}

params = []
keys = Object.keys(query)
for key in keys
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.prevPage) : query[key]))
links.prevPage = results.pagination.prevPage ? {
label: 'Previous',
active: results.pagination.prevPage === results.pagination.currentPage,
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.prevPage) : query[key])).join('&')
url: url + '?' + params.join('&')
} : null

for page in pages
query.page = page

params = []
keys = Object.keys(query)
for key in keys
params.push(key + '=' + encodeURIComponent(query[key]))
links[page] = {
label: page,
active: page === results.pagination.currentPage,
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(query[key])).join('&')
url: url + '?' + params.join('&')
}

params = []
keys = Object.keys(query)
for key in keys
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.nextPage) : query[key]))
links.nextPage = results.pagination.nextPage ? {
label: 'Next',
active: results.pagination.nextPage === results.pagination.currentPage,
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.nextPage) : query[key])).join('&')
url: url + '?' + params.join('&')
} : null

params = []
keys = Object.keys(query)
for key in keys
params.push(key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.lastPage) : query[key]))
links.lastPage = {
label: 'Last',
active: results.pagination.lastPage === results.pagination.currentPage,
url: url + '?' + Object.keys(query).map(do(key) key + '=' + encodeURIComponent(key == 'page' ? (results.pagination.lastPage) : query[key])).join('&')
url: url + '?' + params.join('&')
}

results.pagination.links = links
Expand Down
5 changes: 4 additions & 1 deletion src/Environment/Repository.imba
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ export default class Repository
const results = output.match(/\$\{(.*?)\}/g)

if !isEmpty(results)
results.forEach do(variable)
for variable in results
output = output.replace(variable, self.variables[variable.slice(2, -1)])

# results.forEach do(variable)
# output = output.replace(variable, self.variables[variable.slice(2, -1)])

if isEmpty(output) then return default

['true', 'false'].includes(output.toLowerCase!) ? output = JSON.parse(output) : (output === 'null' ? null : output)
2 changes: 1 addition & 1 deletion src/Foundation/Application.imba
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ export default class Application
resolver.register!

if resolver.context && Array.isArray(resolver.context)
resolver.context.forEach do(context)
for context in resolver.context
self.context.inject(context)
8 changes: 6 additions & 2 deletions src/Foundation/Console.imba
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export default class Console
const nodeEnv = args.find do(arg) arg.startsWith('--MODE=')
const nodeEnvValue = nodeEnv ? nodeEnv.split('=')[1] : 'development'

process.argv = process.argv.filter do(arg) !arg.startsWith('--MODE=')
let filteredArgv = []
for arg in process.argv
if !arg.startsWith('--MODE=')
filteredArgv.push(arg)
process.argv = filteredArgv

modes.includes(nodeEnvValue)

Expand All @@ -148,7 +152,7 @@ export default class Console
let host = 'localhost'
let addr = false

args.forEach do(arg)
for arg in args
port = arg.split('=')[1] if arg.startsWith('--port')
host = arg.split('=')[1] if arg.startsWith('--host') || arg.startsWith('-h')
addr = true if arg == '--addr'
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Console/Commands/DbSeedCommand.imba
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class DbSeedCommand < Command
const root = process.cwd!

Output.group { newLine: false }, do
results[0].forEach do(seeder)
for seeder in results[0]
self.message 'info', "Seeder \x1b[1m[{seeder.substring(root.length + 1)}]\x1b[0m ran successfully."

exit!
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Console/Commands/MigrationCommand.imba
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class MigrationCommand < Command

if results[1].length > 0
Output.group { newLine: false }, do
results[1].forEach do(migration)
for migration in results[1]
self.message 'info', "<fg:green>{action === 'rollback' ? 'Rollback' : 'Migrate'}:</fg:green> {migration}"

if exitOnEnd
Expand Down
5 changes: 3 additions & 2 deletions src/Foundation/Console/Commands/PackagePublishCommand.imba
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export class PackagePublishCommand < Command
def handle
let tags\string[] = self.option('tag').split(',')

tags.forEach do(optTag) self.persist optTag
for optTag in tags
self.persist optTag

self.exit!

Expand All @@ -75,7 +76,7 @@ export class PackagePublishCommand < Command
if typeof self.publisher[optTag] !== 'object'
return self.write "<fg:red>{optTag} is missing paths.</fg:red>"

Object.keys(self.publisher[optTag].paths).forEach do(entry)
for entry in Object.keys(self.publisher[optTag].paths)
const file = join self.package, self.publisher[optTag].paths[entry]

if existsSync(entry) && !self.option('force', false)
Expand Down
10 changes: 7 additions & 3 deletions src/Foundation/Console/Commands/RouteListCommand.imba
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ export class RouteListCommand < Command
const list = []
const methods = self.option('method') ? (Array.isArray(self.option('method')) ? self.option('method') : [self.option('method')]) : ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', 'TRACE', 'CONNECT']

const routes = self.app.routes!.filter(do(route)
methods.map(do(method) method.toUpperCase!).includes(route.method.toUpperCase!)
)
let normalizedMethods = []
for method in methods
normalizedMethods.push(method.toUpperCase!)
let routes = []
for route in self.app.routes!
if normalizedMethods.includes(route.method.toUpperCase!)
routes.push(route)

if self.option('legacy')
self.table(routes)
Expand Down
3 changes: 2 additions & 1 deletion src/Foundation/Console/Commands/ShellCommand.imba
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class ShellCommand < Command
imbaRepl.registerCallback do(ctx)
const context = app.context.registered

Object.keys(context).forEach do(key) if !ctx[key] then ctx[key] = context[key]
for key in Object.keys(context)
if !ctx[key] then ctx[key] = context[key]

const server\REPLServer = await imbaRepl.run!

Expand Down
21 changes: 14 additions & 7 deletions src/Http/Kernel.imba
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ export default class Kernel
const middlewareAliases = self.middlewareAliases ?? self.routeMiddleware

# get route grouped middleware list.
Object.values((_middleware ? _middleware : route.middleware) || []).forEach do(middleware)
middlewareArr = Object.values((_middleware ? _middleware : route.middleware) || [])
for middleware in middlewareArr
if typeof middleware === 'string'
if typeof middleware.split(':')[1] === 'string' then params = middleware.split(':')[1].split(',')

middleware = middleware.split(':')[0]

if self.middlewareGroups[middleware]
const groupedList = self.middlewareGroups[middleware]

Object.values(groupedList).forEach do(match)
const groupedArr = Object.values(groupedList)
for match in groupedArr
if typeof match == 'string' && typeof match.split(':')[1] === 'string'
params = match.split(':')[1].split(',')
match = match.split(':')[0]
Expand Down Expand Up @@ -171,8 +171,8 @@ export default class Kernel
def hasRoutes router\FastifyInstance, config
for route in Route.all!
if isArray(route.action) || isFunction(route.action) || isClass(route.action) || route.action.constructor.name === 'AsyncFunction'
router.route({
method: route.method.toUpperCase!
const domainPayload = {
method: route.method == 'any' ? ['DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT'] : route.method.toUpperCase!
url: route.path
handler: do(req\FastifyRequest, reply\FastifyReply)
const request = req.#context
Expand All @@ -198,7 +198,14 @@ export default class Kernel

await self.resolveMiddleware('timeout', route, request, reply, config)

})
}

if route.domain
domainPayload.constraints = {
host: route.domain
}

router.route(domainPayload)
else
routes.invalid.push(route.path)

Expand Down
9 changes: 3 additions & 6 deletions src/Http/Middleware/TransformsRequest.imba
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export default class TransformsRequest

def clean request
if (request.request.body && request.request.body.constructor === ({}).constructor)
const results = Object.keys(request.request.body).map do(key)
let results = []
for key in Object.keys(request.request.body)
let value = request.request.body[key]

if except.includes(key) == false
value = transform(key, request.input(key))

{
[key]: value
}
results.push({ [key]: value })

let output = {}

Expand Down
42 changes: 30 additions & 12 deletions src/Http/Request/FileCollection.imba
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ export default class FileCollection
* @returns {void}
*/
def each callback\function, _this\null
if isEmpty(_this) then return self._object.forEach callback, _this
if isEmpty(_this)
for file in self._object
callback file, _this
return

self._object.forEach callback
for file in self._object
callback file

/**
* Calls a defined callback function on each File of an array, and returns an array that contains the results.
Expand All @@ -80,9 +84,14 @@ export default class FileCollection
* @returns {File[]}
*/
def map callback\function, _this\null
if isEmpty(_this) then return self._object.map callback, _this

self._object.map callback
let result = []
if isEmpty(_this)
for file in self._object
result.push(callback(file, _this))
return result
for file in self._object
result.push(callback(file))
return result

/**
* Returns the files of an array that meet the condition specified in a callback function.
Expand All @@ -92,9 +101,16 @@ export default class FileCollection
* @returns {File[]}
*/
def filter callback\function, _this\null
if isEmpty(_this) then return self._object.filter callback, _this

self._object.filter callback
let result = []
if isEmpty(_this)
for file in self._object
if callback(file, _this)
result.push(file)
return result
for file in self._object
if callback(file)
result.push(file)
return result

/**
* Filter files using the where condition.
Expand Down Expand Up @@ -123,8 +139,10 @@ export default class FileCollection
*/
def get
let filtered = self._object

for condition\{ key: string, value: any } in self._conditions
filtered = filtered.filter do(file) file[condition.key] == condition.value

filtered
let temp = []
for file in filtered
if file[condition.key] == condition.value
temp.push(file)
filtered = temp
return filtered
6 changes: 3 additions & 3 deletions src/Http/Request/FormRequest.imba
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export default class FormRequest
def setHeaders headers\object
const req = this

Object.keys(headers).forEach do(value)
const headerKeys = Object.keys(headers)
for value in headerKeys
req.setHeader(value, headers[value])

this
Expand Down Expand Up @@ -342,9 +343,8 @@ export default class FormRequest

const body\object = this.body!

keys.forEach do(key)
for key in keys
const value = body[key]

if value
Object.assign response, {
[key]: value
Expand Down
Loading