<commit_before>import { _original, initModel } from "./object-model.js"
import { extend, has, isFunction, proxifyFn, proxifyModel, setConstructor } from "./helpers.js"

export const initListModel = (base, constructor, def, init, clone, mutators, otherTraps = {}) => {

	let model = function (list = model.default) {
		list = init(list)

		if (model.validate(list)) return proxifyModel(list, model, Object.assign({
			get(l, key) {
				if (key === _original) return l

				let val = l[key];
				return isFunction(val) ? proxifyFn(val, (fn, ctx, args) => {
					if (has(mutators, key)) {
						if (mutators[key]) args = mutators[key](args) // autocast method args

						let testingClone = clone(l)
						fn.apply(testingClone, args)
						model.validate(testingClone)
					}

					return fn.apply(l, args)
				}) : val
			}
		}, otherTraps))
	}

	extend(model, base)
	setConstructor(model, constructor)
	initModel(model, def)
	return model
}<commit_msg>perf: add cast mode to list models<commit_after>import { _original, MODE_CAST, initModel } from "./object-model.js"
import { extend, has, isFunction, proxifyFn, proxifyModel, setConstructor } from "./helpers.js"

export const initListModel = (base, constructor, def, init, clone, mutators, otherTraps = {}) => {

	let model = function (list = model.default, mode) {
		list = init(list)

		if (mode === MODE_CAST || model.validate(list)) {
			return proxifyModel(list, model, Object.assign({
				get(l, key) {
					if (key === _original) return l

					let val = l[key];
					return isFunction(val) ? proxifyFn(val, (fn, ctx, args) => {
						if (has(mutators, key)) {
							if (mutators[key]) args = mutators[key](args) // autocast method args

							let testingClone = clone(l)
							fn.apply(testingClone, args)
							model.validate(testingClone)
						}

						return fn.apply(l, args)
					}) : val
				}
			}, otherTraps))
		}
	}

	extend(model, base)
	setConstructor(model, constructor)
	initModel(model, def)
	return model
}
{'fraction_non_alphanumeric': 0.14091595369904378, 'fraction_numerical': 0.0, 'mean_word_length': 3.4573991031390134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6566729', 'n_tokens_mistral': 787, 'n_tokens_neox': 653, 'n_words': 174}